Click here to Skip to main content
15,943,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,


SQL
Select NewDate INTO #MyTable from @Months
--while(NewDate<12)
select convert( varchar(50), NewDate, 103 ) as 'NewDate' from #MyTable
drop table #MyTable


As in the above, I have a temporary table from which I am getting the the dates(values) for a column called 'NewDate'. As:

output:
VB
NewDate
07/01/2011
07/02/2011
07/03/2011
07/04/2011
07/05/2011



Here I need to loop through all the values of NewDate in order to display them in a column format.. As:

VB
NewDate  07/01/2011 07/02/2011 07/03/2011 07/04/2011 07/05/2011



Please any one suggest me, how to use the looping and get the rows(values) as columns. I don't want to use PIVOT.

Regards,
Posted
Updated 8-Mar-11 20:39pm
v5

Some solutions here[^] might give you some ideas.
 
Share this answer
 
Comments
Raj.rcr 8-Mar-11 23:52pm    
No, I want to use the loop to get display result in the format I asked.. I have gone through the link, there is no looping condition at all..
Generally column to rows or Rows to colums, use PIVOT method. You can include format on the query or after pivoting.

It may be easier and better to do formatting after pivoting, because pivoting itself is a costly operation and doesn't need to put more load on it.

Here is the Microsoft documentation of pivoting method

http://msdn.microsoft.com/en-us/library/ms177410.aspx[^]
 
Share this answer
 
Comments
Raj.rcr 9-Mar-11 1:03am    
I am given the task not to use PIVOT... Can u plz give me an idea using the loop, where we can use alter table and exec sp?

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