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)
 split collumn into 2 differents

Author  Topic 

IBoonZ
Yak Posting Veteran

53 Posts

Posted - 2009-03-16 : 10:47:57
Hi i have another question :).

Following data :

ID / TYPE
1 / Product
2 / Product
3 / Suite
4 / Suite

Now i want if the type is 'product', the ID goes to
a new collumn called Product, and if the type is 'Suite', i want
the ID to go to a new Collumn called Suite.


So is it possible to get these collums through a CASE Function, because i already had my data split up in 2 collums, but that was with a Join function, I just copied my tables 2 times and gave them new names. But when I try to link other tables to this table, i got Double data. So thats why i need it to be separated into a CASE function.

Hope this question is not too chaotic

Ty

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-16 : 11:00:15
SELECT ID, [Type], CASE WHEN [Type] = 'Product' THEN ID ELSE NULL END AS Product,
CASE WHEN [Type] = 'Suite' THEN ID ELSE NULL END AS Suite
FROM Table1



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -