求一条简单的SQL语句

songjinxi123 2010-01-30 05:43:07
表:tb1
列:col1,col2
传入参数:par

当col1有匹配par的值,那么那一行的col2的数值加1
当col1没有匹配par的值,那么插入新行,新行的内容为col1=par,col2=0
...全文
65 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dls349920923 2010-01-30
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 rucypli 的回复:]
create proc test
@par varchar(10)
as
if exists (select 1 from tb1 where col1=@par)
  update tb1 set col2 = col2 + 1 where col1=@par
else
  insert into tb1 values(par,0)
[/Quote]
up
feixianxxx 2010-01-30
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 rucypli 的回复:]
create proc test
@par varchar(10)
as
if exists (select 1 from tb1 where col1=@par)
  update tb1 set col2 = col2 + 1 where col1=@par
else
  insert into tb1 values(par,0)
[/Quote]
。。。。
rucypli 2010-01-30
  • 打赏
  • 举报
回复
create proc test
@par varchar(10)
as
if exists (select 1 from tb1 where col1=@par)
update tb1 set col2 = col2 + 1 where col1=@par
else
insert into tb1 values(par,0)

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧