Created
June 30, 2011 18:55
-
-
Save jdaigle/1056910 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SplitGuids]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) | |
DROP FUNCTION [dbo].[SplitGuids] | |
GO | |
CREATE FUNCTION [dbo].[SplitGuids] | |
( | |
@List varchar(2000) | |
) | |
RETURNS | |
@ParsedList table | |
( | |
ID uniqueidentifier | |
) | |
AS | |
BEGIN | |
DECLARE @ID varchar(38), @Pos int | |
SET @List = LTRIM(RTRIM(@List))+ ',' | |
SET @Pos = CHARINDEX(',', @List, 1) | |
IF REPLACE(@List, ',', '') <> '' | |
BEGIN | |
WHILE @Pos > 0 | |
BEGIN | |
SET @ID = LTRIM(RTRIM(LEFT(@List, @Pos - 1))) | |
IF @ID <> '' | |
BEGIN | |
INSERT INTO @ParsedList (ID) | |
VALUES (CAST(@ID AS uniqueidentifier)) --Use Appropriate conversion | |
END | |
SET @List = RIGHT(@List, LEN(@List) - @Pos) | |
SET @Pos = CHARINDEX(',', @List, 1) | |
END | |
END | |
RETURN | |
END | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment