Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Using columns in same query

Author  Topic 

yanivtz
Starting Member

1 Post

Posted - 2005-11-15 : 12:40:15
I am rewriting queries from Access to MSSQL.

Can I do this in MSSQL:

Select 3 as A, 2 as B, A-B as C
?

Thank you

Vivaldi
Constraint Violating Yak Guru

298 Posts

Posted - 2005-11-15 : 12:52:31
yes

________________________________________________

SQL = Serious Quaffing of Liquor
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-11-15 : 13:02:27
No

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-11-15 : 13:04:47
SELECT A, B, A-B AS C FROM (SELECT 3 AS A, 2 AS B) AS XXX



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

Vivaldi
Constraint Violating Yak Guru

298 Posts

Posted - 2005-11-15 : 13:19:11
quote:
Originally posted by X002548

SELECT A, B, A-B AS C FROM (SELECT 3 AS A, 2 AS B) AS XXX



Brett

8-)



So you CAN do it in MSSQL....

________________________________________________

SQL = Serious Quaffing of Liquor
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-11-15 : 13:57:04
quote:
Originally posted by yanivtz

Can I do this in MSSQL:

Select 3 as A, 2 as B, A-B as C



No, you can't...I used a derived table...

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

Vivaldi
Constraint Violating Yak Guru

298 Posts

Posted - 2005-11-15 : 14:01:48
quote:
Originally posted by X002548

quote:
Originally posted by yanivtz

Can I do this in MSSQL:

Select 3 as A, 2 as B, A-B as C



No, you can't...I used a derived table...

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam




A derived table is not something in MSSQL?
I have been misinformed.

________________________________________________

SQL = Serious Quaffing of Liquor
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-11-15 : 15:06:28
No you have to use a derived table to do that.

You can not reference an alias (although I've seen some strange things) as a column as was suggested by the original poster.

That is what you can not do.



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-16 : 01:09:26
>>Select 3 as A, 2 as B, A-B as C

Not until you use derived table
But can use without it when you use order by

Select 3 as A, 2 as B order by A


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -