求一SQL或存储过程

xuming120 2011-09-13 02:32:47


ID label count
1 电影 0
2 生活 1
3 财经 2
4 互联网 1

我想根据参数更新count列的值。 比如: 传入参数@label为“电影、生活、互联网”。当有相同的就更新 count + 1 。
sql语句或者存储过程都可以。
...全文
68 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuming120 2011-09-13
  • 打赏
  • 举报
回复
速度真快。。谢了。结贴
NBDBA 2011-09-13
  • 打赏
  • 举报
回复
update tab set
[count] = isnull([count],0)+ 1
where charindex(label ,@label )>0
--小F-- 2011-09-13
  • 打赏
  • 举报
回复
----------------------------------------------------------------
-- Author :fredrickhu(小F,向高手学习)
-- Date :2011-09-13 14:38:38
-- Verstion:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86)
-- Apr 22 2011 11:57:00
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([ID] int,[label] varchar(6),[count] int)
insert [tb]
select 1,'电影',0 union all
select 2,'生活',1 union all
select 3,'财经',2 union all
select 4,'互联网',1
--------------开始查询--------------------------
declare @s varchar(100)
set @S='电影、生活、互联网'

update tb set count=count+1 where charindex(label,@s)>0
select * from [tb]
----------------结果----------------------------
/* ID label count
----------- ------ -----------
1 电影 1
2 生活 2
3 财经 2
4 互联网 2

(4 行受影响)

*/
--小F-- 2011-09-13
  • 打赏
  • 举报
回复
declare @s varchar(100)
set @S='电影、生活、互联网'

update tb set count=count+1 where charindex(label,@s)>0

27,579

社区成员

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

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