0

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

5
  • 1
    That's not a column alias - that's string substitution Commented Dec 8, 2009 at 21:41
  • Oups! I now got the point! But string substitution is the only way? Another way of referencing the value does not exist? (I am sorry about my English). Commented Dec 8, 2009 at 21:45
  • Depends on what do you exactly want to do with the data. You could have a trigger that updates the other column, you could have a computed column. Commented Dec 8, 2009 at 21:47
  • 3 dollars for blue ball? Commented Dec 8, 2009 at 22:08
  • Don't worry about it! You may order the red one! :) Commented Dec 9, 2009 at 22:31

2 Answers 2

2

The manual way to do so would be:

select replace(coldescription,'%colPrice%',colprice) from table
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.