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 2005 Forums
 Transact-SQL (2005)
 Help with CTE...

Author  Topic 

sqlilliterate
Starting Member

40 Posts

Posted - 2009-08-24 : 14:18:52

Hi all,

Help me with a query using CTE to arrive my desired output...

Table 1

id num
---- ----
a 1
b 2
c 3

Table 2

id num
---- ----
a 5
b 8
c 9

Expected Output

num mx
---- ----
5 8 --> num + max num value from table1 (5+3)
8 16 --> num + previous max value (8+8)
9 25 --> num + previous max value (9+16)



I would not like to use a while loop or a temp table for this...

Your thoughts on this would be a great help to me...

Thnx in adv...

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2009-08-24 : 14:37:33
Five steps to CTEs:
http://docs.google.com/present/view?id=ddp5b6rx_104d4jcdjw5

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-08-25 : 12:47:53
thx alot blindman!!!


Hope can help...but advise to wait pros with confirmation...
Go to Top of Page
   

- Advertisement -