首先创建一个分隔字符串函数:
1 create function SplitIn(@c varchar(2000),@split varchar(2)) 2 returns @t table(col varchar(20)) 3 as 4 begin 5 while(charindex(@split,@c)<>0) 6 begin 7 insert @t(col) values (substring(@c,1,charindex(@split,@c)-1)) 8 set @c = stuff(@c,1,charindex(@split,@c),'') 9 end 10 insert @t(col) values (@c) 11 return 12 end
第二,在存储过程中使用SplitIn函数
1 select @TeamRoomCount = COUNT(Work_GuestAccount.AccountID) FROM Work_GuestAccount INNER JOIN 2 Work_GuestEntryIndex ON Work_GuestAccount.EntryID = Work_GuestEntryIndex.EntryID 3 WHERE (Work_GuestEntryIndex.TeamID <> '') AND (Work_GuestEntryIndex.TeamID IS NOT NULL) 4 AND (Work_GuestAccount.RoomID IN (select col from SplitIn(@TeamRoomNo,',')))
转载于:https://my.oschina.net/u/2607133/blog/599007