SQL SERVER 小技巧(不用exec实现in()的功能)

declare @x varchar(20)
SET @x='1,2,3'
SELECT @x
select * from data0001 where charindex(','+ltrim(rkey)+',',','+@x+',')>0
 
--======================

SQL SERVER 小技巧(多行数据转字符串a,b,c...的写法)

declare @Colstr varchar(max)
select @Colstr = isnull(@Colstr + ',' , '' ) + isnull(name , '' )  
from sys.columns WHERE object_id = OBJECT_ID('tablename')
 
select @Colstr as Colstr
05-02 04:59