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 2005 Forums
 Transact-SQL (2005)
 Retrieve values from comma code

Author  Topic 

abhit_kumar
Posting Yak Master

147 Posts

Posted - 2012-04-03 : 07:42:41
Dear All Experts,

Currently in one of table field "Pay ID" have the data like in below patterns.

1,3,5
4
8,6
9
3,5
1,5
11,12

Now for every above number there is specific description, now i want to change the description from number like:-

1,3,5 = Good, Better, Best
9 = Like
3,5=Better,Best

Please guide me how to do this.

Regards,
Avijit

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-04-03 : 09:05:39
do you have another table that translate the value to description ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

abhit_kumar
Posting Yak Master

147 Posts

Posted - 2012-04-03 : 11:02:12
Yes, i have.

How to do it?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-04-03 : 12:11:46
[code]
;with cte as
(
select t1.PayID, c.stringval, t2.PayDesc
from tbl1 t1
cross apply CSVTable(t1.PayID) c
inner join tbl2 t2 on c.stringval = t2.PayID
)
select c.PayID,
Descrip = stuff((
select ',' + PayDesc
from cte x
where x.PayID = c.PayID
for xml path('')
), 1, 1, '')
from cte c
group by c.PayID
[/code]

get CSVTable from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25830&SearchTerms=CSVTable


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -