Skip to content

Instantly share code, notes, and snippets.

@jdaigle
Created June 30, 2011 18:55
Show Gist options
  • Save jdaigle/1056910 to your computer and use it in GitHub Desktop.
Save jdaigle/1056910 to your computer and use it in GitHub Desktop.
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