TSQl Column Alias question

I would like to use multiple column alias names in the Insert and Update commands.  

Here is an example of what I am trying to do:

Suppose there is a Column F9.  I would like to be able to update column F9 by using field names like [Color] or [Color Code] or [CLR CD].

Is this possible?   If so, how?   Thanks
Tom SageAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
JoeNuvoConnect With a Mentor Commented:
you can do this by using view

for ex

CREATE VIEW [ViewName]
AS
SELECT <other fields list>, F9 as Color, F9 as [Color Code], F9 as [CLR CD]
FROM <table name>
GO

and then you can update view with any field name you like
UPDATE <ViewName>
SET color = <value>  (or [Color Code] = <value>  or  [CLR CD] = <value> )
[WHERE condition]

0
 
AliSyedCommented:
select f9 as [Color],F9 as [Color Code], F9 as [CLR CD].
0
 
lundnakCommented:
Column aliases work for the select statement.  However for update statement you can't use them on the left-side of the set clause.
0
 
Tom SageAuthor Commented:
Joe,

Thanks for the excellent information.  This will help a lot.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.