Skip to content

Instantly share code, notes, and snippets.

@iknowkungfoo
Created September 7, 2018 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iknowkungfoo/c73bccbc43cfadf84e91397e14c97f20 to your computer and use it in GitHub Desktop.
Save iknowkungfoo/c73bccbc43cfadf84e91397e14c97f20 to your computer and use it in GitHub Desktop.
/*
******* Run on both main and US Soccer databases ********
*/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION dbo.integerListToTable ( @strString varchar(max))
RETURNS @Result TABLE(LIST_ID BIGINT)
AS
/*------------------------------------------------------------------
** Name: [dbo.integerListToTable]
** Description : Converts a comma-delimited list of integers to a table.
** Example Call :
* DECLARE @strString varchar(max);
* SET @strString = '1,2,3,4,5';
* select * from dbo.integerListToTable(@strString);
* | LIST_ID |
* | ------- |
* | 1 |
* | 2 |
* | 3 |
* | 4 |
* | 5 |
********************************************************************
MODIFIED DATE MODIFIED BY DESCRIPTION OF REVISION
2018-08-23 Adrian Moreno Creation
********************************************************************
------------------------------------------------------------------*/
BEGIN
DECLARE @x XML
SELECT @x = CAST('<A>'+ REPLACE(@strString,',','</A><A>')+ '</A>' AS XML)
INSERT INTO @Result
SELECT
t.value('.', 'int') AS inVal
FROM
@x.nodes('/A') AS x(t)
RETURN
END
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment