首先创建一个分隔字符串函数:
1 create function SplitIn@c varchar2000),@split varchar2)) 2 returns @t tablecol varchar20)) 3 as 4 begin 5 whilecharindex@split,@c)<>0) 6 begin 7 insert @tcol) values substring@c,1,charindex@split,@c)-1)) 8 set @c = stuff@c,1,charindex@split,@c),'') 9 end 10 insert @tcol) values @c) 11 return 12 end
第二,在存储过程中使用SplitIn函数
1 select @TeamRoomCount = COUNTWork_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