Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
2 field Table from comma delimited
Message
From
16/10/2002 15:54:43
 
 
To
16/10/2002 15:17:49
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00711833
Message ID:
00711942
Views:
7
The string being passed comes as a single string like this '?UID=N0464A&Section=Auditor&Firm=GenDiesel&AI=None' the result I need looks like so;
_Col1_   |_Col2_
 UID     | N0464A
 Section | Auditor
 Firm    | GenDiesel
 AI      | None 
A foxpro split or similar function would be nice here ... Forgive my unfamiliarity inside SPs. ;/

Thanks for all your help, I didn't mean to become a burden,
Joe.

>Thats pretty straightforward, Joe. Since you're dealing with SQL here, you don't have to deal with recordset issues. Here's an example, assuming that Column 1 and Column 2 are being populated from @Col1SourceVariable and @Col1SourceVariable:
>
>SET @ExecuteString = 'SELECT ' + REPLACE(REPLACE(REPLACE(@Col1SourceVariable, '?',''), '=',',') , '&',',') + REPLACE(REPLACE(REPLACE(@Col2SourceVariable, '?',''), '=',',') , '&',',') + ' INTO NewTable'
>
>But I assume you are getting the original string values from another data source. If so, you will want to load them into a SQL staging table in their raw form, using the Import Wizard in SQL Enterprise Manager. Then change your exec string to look something like this:
>
>SET @ExecuteString = 'SELECT ' + REPLACE(REPLACE(REPLACE(StagingtableCol1Name, '?',''), '=',',') , '&',',') + REPLACE(REPLACE(REPLACE(StagingTableCol2Name, '?',''), '=',',') , '&',',') + ' FROM StagingTable INTO NewTable'
>
>This copies all the rows from StagingTable, cleans up each row and loads it into StagingTable. Note that you don't have to create StagingTable before you do this - SELECT INTO does it for you.
>
>Carl
>>Thanks Carl, I appreciate that much tighter code. Now what I need to do is to get the results into a 2 field table where the rows are filled from the cleaned up string like so 'Row1Col, Row1Co2, Row2Col, Row2Co2, Row3Col, Row3Co2' if I am being clear. I hope. I don't know how to loop through the recordset or create the two col table inside a SP.
>>I really appreciate your help.
>>
>>[snip]
>>>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
~Joe Johnston USA

"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams

Previous
Next
Reply
Map
View

Click here to load this message in the networking platform