Solved

TSQl Column Alias question

Posted on 2010-09-15
4
565 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:MisterT25
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 500 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:MisterT25
ID: 33687044
Joe,

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now