473,372 Members | 1,211 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Using alias in an expression

Hi
I tried to use the alias a1 for the column f1 like this, but it fails:

create table a (f1 int not null primary key)
insert into a (f1) values (2)

select f1 a1 from a where a1 = 2

Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'a1'.

In my real situation f1 is a "pretty complex" calculation, and a1 is an
alias of that.
I wanted to use the alias in the query instead of repeating the calculation
several times.

If this use of alias is not legal, then is there a way to get around this?

TIA
Gunnar V°yenli
EDB-konsulent as
NORWAY
Jul 20 '05 #1
2 3676
Put your aliased column in a derived table query.

SELECT a1
FROM
(SELECT f1 AS a1
FROM A) AS A
WHERE a1 = 2

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2
Thanks alot, David!
Now, its working fine!
-Gunnar
"David Portas" <RE****************************@acm.org> wrote in message
news:Fa********************@giganews.com...
Put your aliased column in a derived table query.

SELECT a1
FROM
(SELECT f1 AS a1
FROM A) AS A
WHERE a1 = 2

--
David Portas
SQL Server MVP
--

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: John | last post by:
Hi all, I am doing the change from having worked in Oracle for a long time to MS SQL server and am frustrated with a couple of simple SQL stmt's. Or at least they have always been easy. The...
2
by: Gunnar Liknes | last post by:
Hi, I am trying to use the result of one expression in an other expression by referring to its alias name. Is this possible? here is the first: if(status>0,0,1) alias 'enabled' and the next:...
1
by: Tooled | last post by:
I am writing a vb.net app that uses ms-access as its database. I need to allow users to create their own custom sql expressions that will eventually be used in their reports. After they have...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
9
by: Ron | last post by:
Hello, Is it required to use Imports System.Runtime.InteropServices to run C++ API code? I ask because I thought I read somewhere that this was required. If it is not required would it...
10
by: Robert | last post by:
How do you get an accurate count of the number of records returned from a query when using linked tables. I have an access 2003 database as a front end to another access 2003 database that...
22
by: Daniel Rucareanu | last post by:
I have the following script: function Test(){} Test.F = function(){} Test.F.FF = function(){} Test.F.FF.FFF = function(){} Test.F.FF.FFF.FFFF = function(){} //var alias = function(){}; var...
5
by: No bother | last post by:
I am using 5.0.26-NT on Windows 2000. I have need to use a reference in the outer from clause in a subquery in the select clause. Consider the following example: Select (select b.baitID from...
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.