views:

80

answers:

2

Is there any way of setting an "Column Alias" in SQL Server?

For Example i have two columns. Description and Price

ID    colDescription                                colPrice
1     Red ball costs %colPrice% dollars             2
2     Blue ball costs %colPrice% dollars            3

The selection of colDescription for ID=2, should fetch

Blue ball costs 3 dollars

+2  A: 

The manual way to do so would be:

select replace(coldescription,'%colPrice%',colprice) from table
Vinko Vrsalovic
A: 

You could use a Computed Column since you're on SQL Server 2005:

http://msdn.microsoft.com/en-us/library/ms191250.aspx

Nissan Fan
It's an extremely fast and efficient mechanism, however I prefer to abstract out presentation and business logic from the data store myself.
Nissan Fan