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 2008 Forums
 Other SQL Server 2008 Topics
 Alter Column Name based on another field value

Author  Topic 

sqlmjkm
Starting Member

14 Posts

Posted - 2013-05-22 : 15:30:19
I'm not sure if I can do this.... I'm trying to change the column heading based on the value of another field.

Something like this:

SELECT Other AS 'Other (describe):' + [OtherText]
FROM [TESTTABLE]


The value of Other is "X"
The value of OtherText is "Football"

So the column heading would look like: "Other (describe): Football"
The value would be "X"

... I know there are much better ways of doing this, just we don't have the option of changing the table format.

The Select statement would only ever return one single record.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-23 : 00:59:19
you cant do this in t-sql unless you use dynamic sql. My guess is this for a reporting need and there are much easier ways to achieve this at your reporting tool end. For example SSRS supports writing expressions for column headers and I would highly recommend doing it at front end if at all possible.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -