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)
 extract comma separated values in column as rows

Author  Topic 

mihir.mone
Starting Member

17 Posts

Posted - 2010-10-20 : 22:15:31
I have 2 tables,
COI, Company

*** COI ***
-------------------
policyno codes
-------------------
1 xxx,yyy
2 yyy

*** Company ***
---------------
Code Name
---------------
xxx SOS
yyy CMC


I want to write a query to retrieve which Companies are using the policies

-- Result --
----------------
policyno Name
----------------
1 SOS
1 CMC
2 CMC

I tried with cross join, but I must admin I am not that good with SQL.
Can anyone help me with this?

Mihir.

Sachin.Nand

2937 Posts

Posted - 2010-10-21 : 01:20:27
First of all it is a BAD database design.Please never store values in columns in comma seperated format.

As for your requirement write a table valued function to split the codes which will return codes which you can join with Company table on Code to get the desired result.

PBUH

Go to Top of Page

mihir.mone
Starting Member

17 Posts

Posted - 2010-10-21 : 02:23:32
Thanks Sachin.

I found some other way to generate this report.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-21 : 02:36:17
quote:
Originally posted by mihir.mone

Thanks Sachin.

I found some other way to generate this report.



Can you please let us you what did you use?

PBUH

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-21 : 06:04:28
Solution is given here:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=151893


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -