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.
| Author |
Topic |
|
gosman
Starting Member
4 Posts |
Posted - 2006-05-03 : 08:06:33
|
| Hi AllI'm really new to SQL and would appreciate a solution to the following problem.I have a table that contains 1 record. in that record there is a column called CODES which contains multiple values that are seperated by a comma.C200,C201,C202,C204,C200,C203,C200,C202,C203,C205,C200,C202,C203,C204,C205,C206,C200,C201,C202I need a solution to select all values from CODES that are distinct so I end up with the following.C200,C201,C202,C203,C204,C205,C206Any help would be really appreciated. Please bear in mind I'm a complet novice. |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-05-03 : 08:46:26
|
| This is a bad database design, which is why it is so difficult to query the data. Can you change the way you are storing this information? |
 |
|
|
gosman
Starting Member
4 Posts |
Posted - 2006-05-03 : 08:55:55
|
| We are actually in the process of having the apllication redeveloped, but at the moment I'm stuck with the data in this format so I need a solution. |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-05-03 : 09:11:11
|
| See if this helps:http://www.sqlteam.com/item.asp?ItemID=2652That shows you how to take your CSV data and parses it into multiple rows. From there, you can use DISINTCT or GROUP BY to get distinct values. You will then need to concatenate the results back together to get your new CSV strings. If it is at all possible to avoid that last step, I highly recommend it. I hope that when the application is re-developed you will be able to normalize your tables, then things will be much easier for you. Then your SQL will be much easier and shorter, it will be much more efficient, you can have referential integrity, and so on. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|