SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 extract comma separated values in column as rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mihir.mone
Starting Member

17 Posts

Posted - 10/20/2010 :  22:15:31  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

2937 Posts

Posted - 10/21/2010 :  01:20:27  Show Profile  Reply with Quote
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 - 10/21/2010 :  02:23:32  Show Profile  Reply with Quote
Thanks Sachin.

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

Sachin.Nand
Flowing Fount of Yak Knowledge

2937 Posts

Posted - 10/21/2010 :  02:36:17  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8529 Posts

Posted - 10/21/2010 :  06:04:28  Show Profile  Visit webfred's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000