Home All Groups Group Topic Archive Search About

Pivot SQL Statement in SQL SERVER 2000

Author
4 Nov 2005 8:55 PM
harish
I have a table temp1 with the following data:

a    b    c    d
10    11    888    991
10    11    888    992

How do I pivot this such that the output be

10    11    888        991          992

Thanks
harish

Author
4 Nov 2005 9:06 PM
Aaron Bertrand [SQL Server MVP]
With the extremely limited information you've provided,

SELECT a,b,c,MIN(d),MAX(d)
FROM temp1
GROUP BY a,b,c

If you want a more complete answer, please provide a more complete question.
http://www.aspfaq.com/5006



Show quote
"harish" <harish.prabh***@gmail.com> wrote in message
news:1131137736.316980.221230@g49g2000cwa.googlegroups.com...
>I have a table temp1 with the following data:
>
> a b c d
> 10 11 888 991
> 10 11 888 992
>
> How do I pivot this such that the output be
>
> 10 11 888        991          992
>
> Thanks
> harish
>
Author
4 Nov 2005 9:09 PM
harish
Hey Thanks

But if i have more than 2 rows for one key (a,b,c) the this will not
work.
In that case how do I do it?
Author
4 Nov 2005 9:14 PM
Aaron Bertrand [SQL Server MVP]
> But if i have more than 2 rows for one key (a,b,c) the this will not
> work.

See how helpful more information would have been?

> In that case how do I do it?

http://www.aspfaq.com/2462

Again, if you want a more useful answer, provide a more detailed question.
See the link I posted in my previous response.
Author
4 Nov 2005 9:54 PM
harish
Hey thanks a lot
that was helpful
Author
4 Nov 2005 11:08 PM
Erland Sommarskog
harish (harish.prabh***@gmail.com) writes:
> But if i have more than 2 rows for one key (a,b,c) the this will not
> work.
> In that case how do I do it?

Books Online has a section on it:

Accessing and Changing Relational Data
   Advanced Query Concepts
      Transact-SQL Tips
          Cross-Tab Reports


--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Author
6 Nov 2005 2:52 PM
Pike
The more things change the more they remain then same:)

Check out THE Rac utility @
www.rac4sql.net

AddThis Social Bookmark Button