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.
Author |
Topic |
nietzky
Yak Posting Veteran
75 Posts |
Posted - 2012-07-19 : 10:52:38
|
I have a derived table TIME_MASTERthat looks like this:Fullname 7/14/2012 7/7/2012 6/29/2012s1/sdhd1 62.12 79.14 78.33s3/sdhd1 22.01 100s5/sdhd1 27.66 90.98 92.46s2/sdhd1 99.10 100 99.89Is it possible to sort always 2nd dynamically created column in desc order by knowing that the date headers - date columns are generated always automatically? Sample sorted output of this would be: Fullname 7/14/2012 7/7/2012 6/29/2012s2/sdhd1 99.10 ... ...s1/sdhd1 62.12 ...s5/sdhd1 27.66 ... ...s3/sdhd1 22.01 ... ...thsi is how this table is derived:declare @temp1 table(FullName varchar(455),[1 year] varchar(20),[6 months] varchar(20)select t.[1 year], t.[6 months], o.* INTOTIME_MASTERfrom HIST_MASTER o LEFT JOIN @temp1 t ON o.Fullname = t.FullName |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-07-19 : 11:00:15
|
You can add ORDER BY 2 DESC. The 2 indicates to SQL Server to sort by the second column in the select list. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-19 : 11:11:10
|
hmm...why is left joined table columns at first? also you're not even using order by. then how can you guarantee order of retrieved data?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
nietzky
Yak Posting Veteran
75 Posts |
Posted - 2012-07-19 : 11:47:43
|
Thank you, problem solved. |
 |
|
|
|
|