Solved

TSQl Column Alias question

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL with ODBC 5 35
VBScript Write Column Headers 3 36
Find SQL query used by application 3 17
SQL Count issue 20 10
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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

776 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