Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Parsing a string in SP

Author  Topic 

yossibaram
Yak Posting Veteran

82 Posts

Posted - 2002-11-26 : 10:10:47
Hi,
Is it possible to parss a string in a SP.
I have 2 tables:
1.A staging table that containes one column (with many rows). that column contains a string ex. aaaa bb ccccc ff tttttt
2. The destination table that containes 5 columns.
I need to insert the data from the staging table to the other.

CREATE PROCEDURE Lan_BuildTable
AS
SELECT
Data1 = substring ( Record_Line , 1,5 ),
Data2 = substring ( Record_Line , 6,2 ),
Data3 = substring ( Record_Line , 8,6 ),
Data4 = substring ( Record_Line , 14,2 ),
Data5 = substring ( Record_Line , 16,20 )
FROM Staging_Table

My problem is that i need to draw the above valuse from inside the buffer in the staging table.
Can i do it?
Thanks


robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-11-26 : 10:16:57
Take a look at these articles:

http://www.sqlteam.com/SearchResults.asp?SearchTerms=csv

There are numerous techniques you can use, and they can be adapted to parse on any character, not just a comma.

Go to Top of Page

yossibaram
Yak Posting Veteran

82 Posts

Posted - 2002-11-27 : 02:41:39
quote:

Take a look at these articles:

http://www.sqlteam.com/SearchResults.asp?SearchTerms=csv

There are numerous techniques you can use, and they can be adapted to parse on any character, not just a comma.





Thanks,
I used the following links but it didn't help me.
The given code is for parsing 1 string.
I have the staging table (with one column)that contains a buffer of values. Number of values and position of each value are not known to me.
Using for example
SELECT
Data1 = substring ( Record_Line , 1,7 ),
Data2 = substring ( Record_Line , 8,11 )
FROM Staging_Table

is great but i do not know the start position and length.
The Record_Line should include ALL the rows in the Staging table not just one string.
Can you help me with that?
Thanks
Yossi

Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-11-27 : 07:16:30
After reading the articles Rob suggested, what did you try? Your answer is in those articles. You gotta bring some effort to the table.

Jay White
{0}
Go to Top of Page
   

- Advertisement -