Hi,
I have a table with only 1 colum. Is it possible to tansform it into a
multi-colums tabel using a SQL SELECT query?
Col
--
1
2
3
4
5
Cols in new table
--
1,2,3
4,5, Nul
Any assistance is highly appreceiated
Larry
larry@.widextech.comTry,
create table t1 (
c1 int not null
)
go
insert into t1 values(1)
insert into t1 values(2)
insert into t1 values(3)
insert into t1 values(4)
insert into t1 values(5)
go
select
max(case when (c1 % 3) = 1 then c1 else null end) as c1,
max(case when (c1 % 3) = 2 then c1 else null end) as c2,
max(case when (c1 % 3) = 0 then c1 else null end) as c3
from
t1
group by
(c1 - 1) / 3
go
drop table t1
go
AMB
"Larry" wrote:
> Hi,
> I have a table with only 1 colum. Is it possible to tansform it into a
> multi-colums tabel using a SQL SELECT query?
> Col
> --
> 1
> 2
> 3
> 4
> 5
> Cols in new table
> --
> 1,2,3
> 4,5, Nul
> Any assistance is highly appreceiated
> Larry
> larry@.widextech.com
>
>|||Does the number of columns always have to be rowcount (or rowcount + 1) / 2?
Or is it always 3 columns?
Why can't the presentation layer do this? I assume this is for presentation
purposes?
"Larry" <larry@.widextech.com> wrote in message
news:uzDDFE3oFHA.4056@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I have a table with only 1 colum. Is it possible to tansform it into a
> multi-colums tabel using a SQL SELECT query?
> Col
> --
> 1
> 2
> 3
> 4
> 5
> Cols in new table
> --
> 1,2,3
> 4,5, Nul
> Any assistance is highly appreceiated
> Larry
> larry@.widextech.com
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment