[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

TSQl Column Alias question

Posted on 2010-09-15
4
Medium Priority
?
577 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Tom Sage
4 Comments
 
LVL 6

Expert Comment

by:AliSyed
ID: 33686199
select f9 as [Color],F9 as [Color Code], F9 as [CLR CD].
0
 
LVL 7

Expert Comment

by:lundnak
ID: 33686301
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
 
LVL 11

Accepted Solution

by:
JoeNuvo earned 2000 total points
ID: 33686775
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
 

Author Closing Comment

by:Tom Sage
ID: 33687044
Joe,

Thanks for the excellent information.  This will help a lot.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question