标签:
CREATE procedure sp_split_string
(
@string NVARCHAR(4000)
)
AS
BEGIN
DECLARE @object_id nvarchar(500)
DECLARE @where nvarchar(500)
DECLARE @i INT
DECLARE @len INT
SET @where = ‘select id from a where 1=1‘
print @string
IF (@string IS NULL) OR (LTRIM(@string) = ‘‘)
RETURN
WHILE CHARINDEX(‘,‘,@string) > 0
BEGIN
SET @len = LEN(@string)
SET @i = CHARINDEX(‘,‘, @string)
SET @object_id = LEFT(@string, @i-1)
SET @where = @where +‘ or id=‘+@object_id
print @where
INSERT INTO a (id) VALUES (@object_id)--少做修改,改成需要的sql语句即可
SET @string = RIGHT(@string, @len - @i)
END
SET @object_id = @string
SET @where = @where +‘ or id=‘+@object_id
print @where
INSERT INTO a (id) VALUES (@object_id)--少做修改,改成需要的sql语句即可
print @where
DECLARE @sql nvarchar(500)
select @sql = @where
exec(@sql)
END
GO
标签:
原文地址:http://www.cnblogs.com/maipaocai/p/5229553.html