27,579
社区成员
发帖
与我相关
我的任务
分享
update tab set
[count] = isnull([count],0)+ 1
where charindex(label ,@label )>0
----------------------------------------------------------------
-- 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 行受影响)
*/
declare @s varchar(100)
set @S='电影、生活、互联网'
update tb set count=count+1 where charindex(label,@s)>0