Solved

TSQl Column Alias question

Posted on 2010-09-15
4
569 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
[X]
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
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

730 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