Click here to Skip to main content
14,691,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one,

Can any one please suggest me how to convert the columns into rows of a temporary rable..?

select convert( varchar(50), NewDate, 103 ) as 'NewDate',AuditTotal AS 'Total Audited' FROM @Months

--------

OUTPUT:

NewDate Total Audited

08/01/2011 0
08/02/2011 1
08/03/2011 2
-----------------

But, I want to the result to be displayed as:

NewDate 08/01/2011 08/02/2011 08/03/2011
Total Audited 0 1 2


Please any one suggest me with pivot or some other idea..

Regards,
Posted
Updated 7-Mar-11 19:58pm
v6

In SQLServer there is a thing called a Pivot Table[^] which is designed to do what you are trying to do.

I have not read all of your stored proc (rather a lot to read) and so do not know if it will fit your scenario.

Still, have a read and see if it is of use.
   
Hi,

Do you mean to convert the rows coming from the query:
select convert( varchar(50), NewDate, 103 ) as 'NewDate',AuditTotal AS 'Total Audited' FROM @Months

If that's the case, you could use UNION as long as the datatypes match, something like:
select convert( varchar(50), NewDate, 103 ) as 'NewDate' FROM @Months
UNION ALL
select AuditTotal AS 'Total Audited' FROM @Months

But frankly this doesn't make sense so perhaps I misunderstood your question.
   
Comments
Raj.rcr 7-Mar-11 23:36pm
   
yes, The for the same select query that u have noticed.. I tried what u posted. But its not working.. I think using 'pivot' can solve the problem.. But, I don't know about pivot
Wendelius 8-Mar-11 0:40am
   
What do you mean by not working? Do you get an error (if so, where) or are the results wrong. If that's the case could you make an example for the original data and the result data you want.

You can find more about Pivot from for example: http://www.codeproject.com/KB/database/Pivot2Columns.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900