Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Invalid Column Name error
Message
 
 
To
11/11/2010 09:09:52
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01488773
Message ID:
01488811
Views:
34
Why did you change the function from what I posted?
CREATE FUNCTION [dbo].[fnSplit]
(@list  VARCHAR(8000),
 @delim CHAR(1) = ','
) RETURNS TABLE AS
RETURN
   WITH csvtbl(START, stop) AS (
     SELECT START = 1,
            stop = CHARINDEX(@delim COLLATE Slovenian_BIN2, @list + @delim)
     UNION ALL
     SELECT START = stop + 1,
            stop = CHARINDEX(@delim COLLATE Slovenian_BIN2,
                             @list + @delim, stop + 1)
     FROM   csvtbl
     WHERE  stop > 0
  )
  SELECT row_number() over (order by Start) as ID, LTRIM(RTRIM(SUBSTRING(@list, START,
                      CASE WHEN stop > 0 THEN stop - START ELSE 0 END)))
         AS VALUE
  FROM   csvtbl
  WHERE  stop > 0
Note the UNION ALL part.

>>>Hmm, I like this approach using the function but I am a bit embarassed to say I am not sure what type of function that would be. Where do I put this? There are several categories under functions.
>>>
>>
>>It should be table valued inline function.
>
>
>Naomi, I get this error when I try to create the function
>
>Msg 252, Level 16, State 1, Procedure fnSplit, Line 10
>Recursive common table expression 'csvtbl' does not contain a top-level UNION ALL operator.
>
>
>Here is the function as I typed it from your post
>
>SET ANSI_NULLS ON
>GO
>SET QUOTED_IDENTIFIER ON
>GO
>
>CREATE FUNCTION [dbo].[fnSplit] 
>(
>	@list varchar(8000),
>	@delim CHAR(1) = ','
>)
>RETURNS Table
>AS
>	RETURN
>	WITH csvtbl(START, stop) AS
>	(
>		SELECT START = 1,
>			Stop = CHARINDEX(@delim COLLATE Slovenian_BIN2,
>							@list + @delim, stop + 1)
>		FROM csvtbl
>		WHERE stop > 0
>	)
>	SELECT row_number() over (order by START) AS ID, LTRIM(RTRIM(SUBSTRING(@list, START,
>								CASE WHEN stop > 0 THEN stop - START ELSE 0 END)))
>			AS VALUE
>	FROM csvtbl
>	WHERE stop > 0
>GO
>
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform