Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

TSQl Column Alias question

Posted on 2010-09-15
4
568 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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

856 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