Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
2 field Table from comma delimited
Message
From
16/10/2002 14:31:58
 
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00711833
Message ID:
00711888
Views:
11
>I have made a SP that takes a string does some replacements to create a pretty comma delimited string. Cuurently I have a single field table, what I need is to get the odd records to be col 1 and even to be col 2. If there is a better way to do it I am open to any ideas. I have included the very simple source here:
>This is my 4th SP, be kind;
>
>CREATE PROC CsvToRSw ( 	
> @CSVstring varchar(500)
>)
>as
>
>    Begin
>    DECLARE @ExecuteString varchar(8000)
>    DECLARE @WorkString varchar(8000)
>
>    	SELECT @ExecuteString = 'Select ''' + REPLACE((SELECT REPLACE((SELECT REPLACE((SELECT REPLACE(@CSVstring, "?","")), "=",",")) , "&",",") ), ",", ''' UNION ALL Select ''' )+''''
>    	
>    -- run the dynamic sql string
>    EXECUTE (@ExecuteString)
>    RETURN @@error
>End


>GO
>
>is there a line continuation char for SPs?
>
>My humble thanks in advance,


Good start Joe, with several ammendments. You don't need a continuation character. Also, you don't need the SELECTs on the right side of the statement and you don't need the UNION. Try this:

SET @ExecuteString = 'SELECT ' + REPLACE(REPLACE(REPLACE('?=&', '?',''), '=',',') , '&',',')

Carl
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform