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)
 help with a query for multiple rows in a select

Author  Topic 

coolcyber
Starting Member

7 Posts

Posted - 2006-02-28 : 10:06:51
hi, Im trying to write a select statement to return 3 rows at a time.
i.e., return the 1st 3 rows as single row(with 3 columns) as output and so on.

Any idea on how this can be done?

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-02-28 : 11:30:23
sample data / desired output please
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2006-03-02 : 12:28:39
[code]declare @matrix table(
[id] int identity(0,1) primary key clustered,
col <data type>
)

insert into @matrix(col) select col from table where ... order by ...

select a.col as col1, b.col as col2, c.col as col3
from @matrix a
join @matrix b on a.[id]/3 = b.[id]/3
join @matrix c on a.[id]/3 = c.[id]/3
where a.col % 3 = 0 and
b.col % 3 = 1 and
c.col % 3 = 2[/code]It needs improvements if big number of rows is going to be returned, but let's see first if i got your requirements right.
Go to Top of Page
   

- Advertisement -