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 the first derived column to the second

Author  Topic 

marileng
Starting Member

28 Posts

Posted - 2002-03-19 : 23:41:31

here is my code

select a=1+1, b = a+2
here is I want the result would be:
a b
2 4


How can I use the

Nazim
A custom title

1408 Posts

Posted - 2002-03-20 : 00:36:13
your question isnt complete.

thought you are looking for something like this

declare @a int
declare @b int
select @a=0,@b=0
select @a=@a+2
select @b=@b+3
select @a,@b

--------------------------------------------------------------


Edited by - Nazim on 03/20/2002 00:41:06
Go to Top of Page

marileng
Starting Member

28 Posts

Posted - 2002-03-20 : 01:12:45
This is my query

Select a =(select table2.balance from table2 where table2.col1=table.col1),balance,b = balance + a from table

a balance b
1 1 2
2 2 4
3 3 6
.
.
.
.
8 8 16





Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-03-20 : 05:10:52
Move the table2 select into the main query:

SELECT a = table2.balance, table.balance, b = table.balance + table2.balance
FROM table
LEFT JOIN table2 ON table2.col1 = table.col1

If table2.col1 is not nullable, the join can be an INNER JOIN.


Edited by - Arnold Fribble on 03/20/2002 05:12:52
Go to Top of Page
   

- Advertisement -