all groups > sql server programming > august 2005 >
You're in the

sql server programming

group:

A SQL query. Can you do that??



RE: A SQL query. Can you do that?? Alejandro Mesa
8/17/2005 2:27:16 PM
sql server programming: Try,

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


[quoted text, click to view]
Re: A SQL query. Can you do that?? Aaron Bertrand [SQL Server MVP]
8/17/2005 5:34:59 PM
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?




[quoted text, click to view]

A SQL query. Can you do that?? Larry
8/17/2005 10:16:40 PM
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


AddThis Social Bookmark Button