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)
 Need Column Name in the result

Author  Topic 

satish.gorijala
Posting Yak Master

182 Posts

Posted - 2009-01-19 : 05:05:13
C1 C2 C3 C4 C5 zcode
12 48 23 02 04 23445


Now i need output as
C3 48
i.e Find out the greatest column number with name.
I am able to get value of column, but how to get column name. My query is as follows.

SELECT MAX(theValue) as Highvalue
FROM Table1 AS t1
UNPIVOT (theValue FOR theCol IN (t1.Col1, t1.Col2, t1.Col3, t1.Col4, t1.Col5, t1.zCode) AS u
where u.zCode = '23445'

my ouput is as follows
Highvalue
48


G. Satish

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-19 : 05:37:26
Cross post http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=118102
Already asked and answered.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2009-01-19 : 05:37:58
I think U Posted It Before in Same Forum Do not Post Dupliacte Entries.............

U Use Here Peso Sir Solution Here,,,,,,

So Dont Post Dupliacte
Go to Top of Page

satish.gorijala
Posting Yak Master

182 Posts

Posted - 2009-01-19 : 05:42:43
Hello Boss i need column name also...not only the value...

quote:
Originally posted by Peso

Cross post http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=118102
Already asked and answered.



E 12°55'05.63"
N 56°04'39.26"




G. Satish
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-19 : 05:51:16
see that peso, peterneo give the column name also in there result set
check once
Go to Top of Page
   

- Advertisement -