最近又忘記存儲過程 除了exec 動態寫法的另外一種,這里記錄一下,方便查找
寫法1,動態語句
CREATE PROCEDURE sp_CountShiftWish @strids varchar (1024) /*strids 是id列表, 類似1,2,3*/ AS exec ('select * from student where id in('+@strids+')') go
寫法2,索引查找
CREATE PROCEDURE sp_CountShiftWish @strids varchar (1024) /*strids 是id列表, 類似1,2,3*/ AS select * from student where charindex(','+ltrim(id)+',',','+@strids+',')>0
go