SHARE
TWEET

Untitled

a guest Sep 17th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. IF EXISTS (SELECT * FROM sysobjects WHERE id=object_id(N'[dbo].[splitstring]') and type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
  2. DROP FUNCTION [dbo].[splitstring]
  3. GO
  4.  
  5. CREATE FUNCTION [dbo].[splitstring] (
  6.     @stringToSplit  VARCHAR(MAX),
  7.     @delimiter  CHAR(1)
  8. )
  9. RETURNS
  10.     @returnList TABLE ( [idx]   int identity(1,1),
  11.                 [Name]  [nvarchar] (500) )
  12. AS
  13. BEGIN
  14.     DECLARE @name   NVARCHAR(255)
  15.     DECLARE @pos    INT
  16.  
  17.     WHILE CHARINDEX(@delimiter, @stringToSplit) > 0
  18.     BEGIN
  19.         SELECT @pos  = CHARINDEX(@delimiter, @stringToSplit)  
  20.         SELECT @name = SUBSTRING(@stringToSplit, 1, @pos-1)
  21.  
  22.         INSERT INTO @returnList
  23.         SELECT @name
  24.  
  25.         SELECT @stringToSplit = SUBSTRING(@stringToSplit, @pos+1, LEN(@stringToSplit)-@pos)
  26.     END
  27.  
  28.     INSERT INTO @returnList
  29.     SELECT @stringToSplit
  30.  
  31.     RETURN
  32. END
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top