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
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
相关文章推荐
- PHP如何获取刚插入数据的ID 和判断SQL语句是否成功执行
- 当需要向数据库插入空值时,sql语句的判断
- 先判断记录是否存在,不存在则将记录插入表的sql语句
- sql语句中插入判断赋值语句
- sql语句:插入的时候判断是否有重复项
- 数据库端防止并发的SQL语句 插入时就判断是否存在
- 【SQL】根据插入语句条件判断插入哪张表,多表插入,2017年
- oracle中 判断是否 有记录 然后插入的sql语句
- SQL 插入语句汇总
- 批量插入更新的 sql语句
- 记一次上万条数据的正确插入更新sql语句
- mysql如何用一条sql语句实现不存在就插入,存在的话则更新
- android中常用的查询、插入、更新、删除等SQL语句以及SQLite数据类型
- 必须会的SQL语句(三) 数据插入
- SQL-插入语句中的‘,”,{
- SQLSERVER ISNULL 函数与判断值是否为空的sql语句
- sql语句判断是否为数字、字母、中文
- python脚本随笔:实现生成插入表的sql语句
- C# asp.net SQL存储过程写法Insert 插入语句,及其在asp.net中的调用方法
- SQL 批量插入数据语句