sql server 2008 变量可以分割吗?
比如说定义一个变量 declare @res varchar(100) set @res='1 2 3 4 5' 可以将@res分割成 '1' '2' '3' '4' '5' 吗? sql?server?2008
[解决办法]
declare @res varchar(100),@tsql varchar(6000)
set @res='1 2 3 4 5'
select @tsql='select * from Student where name like ''%'
+replace(@res,' ','%'' or name like ''%')+'%'' '
print @tsql
-- 结果
/*
select * from Student where name like '%1%' or name like '%2%' or name like '%3%' or name like '%4%' or name like '%5%'
*/