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 2000 Forums
 Transact-SQL (2000)
 Single Column to multiple column

Author  Topic 

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2007-11-24 : 01:12:47
Given with the sample and desired result. Would this be possible without using a cursor and plainly select statements?

Sample data...

select 1 as sID, '01110' as code union all
select 2 as sID, '11110' as code union all
select 3 as sID, '101111' as code

Desired result...

select 1 as sID, 0 as c1, 1 as c2, 1 as c3, 1 as c4, 0 as c5, null as c6 union all
select 2, 1, 1, 1, 1, 0, null union all
select 3, 1,0,1,1,1,1


For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-24 : 01:19:32
use substring() to extract the individual chars


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

Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2007-11-24 : 01:34:33
how about making it a dynamic query? the "code" column's length might vary.

thanks



For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-24 : 01:41:23
then use Dynamic SQL


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

Go to Top of Page
   

- Advertisement -