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
 SQL Server Development (2000)
 parsing issues...how to??

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-09-20 : 07:17:01
Eyoel writes "I had forgotten something...please see below

I have a situation....

I havee

table A

ID Description
1 X
2 y
3 z

I want to update table B that has ID's linked to table A
but the column that has the ID in table B contains ID separated by comma, as in

BID ColumnToBeUpdated
1,2,3 some text:1,2,3
3 anotehrtext:3

So eventually I want table B to look like

BID ColumnToBeUpdated
1,2,3 some text:x,y,Z
3 anothertext:z

I was able to update the values for the single BID ( which is a char ) in table B by doing a simple inner join and using charindex = 0 but I am having problems to parse the value with comma and update accordingly. This is what i have so far...

UPDATE b
SET b.ColumnToBeUpdated = 'some text:' + a.Description
from table B
inner join table A
ON b.bid = a.ID where (CharIndex(',', b.bid, 1) = 0)

I was trying to use cursor to no avail.

Please help !

Eyoel"

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-20 : 07:40:04
Use a function which parses comma-separated values and returns table of values and use this table to join with TableA.

Check the following link for more help:

[url]http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm[/url]

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page
   

- Advertisement -