您的位置:首页 > 数据库

SQL语句判断并插入表

2006-08-30 08:39 323 查看
Declare @num int

set @num =0

while(@num<9)
begin

set @num= @num + 1
if not exists(Select Attrid FROM HVC_Statistics_Setting WHERE Attrid =@num)
begin
INSERT INTO HVC_Statistics_Setting(PortalID,AttrID,AttrName,StringValue,FloatValue)
VALUES (@PortalID,@num,'','',Case
When @num=1 then @TotalAccessed
When @num=2 then @AllArticlesNum
When @num=3 then @AllArticleHits
When @num=4 then @MonthTotalUpdated
When @num=5 then @MonthArticleHits
When @num=6 then @WeekArticleUpdated
When @num=7 then @WeekArticleHits
When @num=8 then @Score
end)
end
else
begin
Update HVC_Statistics_Setting SET
PortalID=@PortalID,
AttrID=@num,
AttrName='',
StringValue='',
FloatValue= Case
When @num=1 then @TotalAccessed
When @num=2 then @AllArticlesNum
When @num=3 then @AllArticleHits
When @num=4 then @MonthTotalUpdated
When @num=5 then @MonthArticleHits
When @num=6 then @WeekArticleUpdated
When @num=7 then @WeekArticleHits
When @num=8 then @Score
end
where Attrid =@num
end
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: