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 2005 Forums
 Transact-SQL (2005)
 storedproc dataset

Author  Topic 

jake85
Starting Member

2 Posts

Posted - 2012-01-17 : 15:02:04
hi, I need to create a dataset from a stored proc that works off the following table structure:

Table: (ordered on A)
A B C
-- -- --
0 1 Val1
0 2 Val2
0 3 Val3
1 1 Val4
1 2 Val5
1 3 Val6
etc....

Result Dataset format: (returns new columns D,E)
A C D E
-- -- -- --
0 Val1 Val2 Val3
1 Val4 Val5 Val6
etc...

Hope this is clear as I'm new to sql and not sure how to illustrate my question. Basicly I need to get the three consecutive rows from the table together in one row.

This is a real show stopper- any help on e how to do it would be greatly appreciated!

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-17 : 15:15:13
what if there are 99 rows for Column A?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-17 : 15:17:20
[code]SELECT
A,
[1] AS [C],
[2] AS [D],
[3] AS [E]
FROM
yourTable
PIVOT
( MAX(c) FOR b IN ([1],[2],[3])) P[/code]
Go to Top of Page

jake85
Starting Member

2 Posts

Posted - 2012-01-19 : 11:12:46
WOW! PIVOT works perfectly for my problem! Thank you so very much for your help sunitabeck!
I'm such a noob I didn't even know PIVOT existed.

@X002548 - well taken, your guide will help me for future posts - thanks!
Go to Top of Page
   

- Advertisement -