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
 General SQL Server Forums
 New to SQL Server Programming
 Two non related queries

Author  Topic 

dotinf
Starting Member

6 Posts

Posted - 2010-02-15 : 19:47:49
Hi, I have two queries. What I am trying to do is use the result of a number from the first query in the second query, but I don't know how to do this.


SELECT acc, cat, dsc, rcp_num
FROM allTran INNER JOIN
allcat ON all.trsCat = allcat.trsCat INNER JOIN
allMast ON allTran.Allnum = allMast.Allnum
WHERE (allTran.amt <> 0)



SELECT trn_num, seq_num
FROM aureline
WHERE (rcp_num = @rcp_num)


What i am trying to achieve is to have 6 columns which will have multiple rcp_num results, but I don't know if there is a way to reference the rcp_num from the first query into the @rcp_num of the second query.

Thank you for your time.

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-02-15 : 20:53:21
Can you show some sample data??

How about joining aureline to the first query?? Something like below...may not be accurate as I dont know which column is from which table...but shud give you some idea?
SELECT     a.acc, b.cat, b.dsc, c.rcp_num,d.trn_num, d.seq_num
FROM allTran a INNER JOIN
allcat b ON a.trsCat = b.trsCat INNER JOIN
allMast c ON a.Allnum = c.Allnum INNER JOIN
aureline b ON d. rcp_num = c. rcp_num
WHERE (allTran.amt <> 0)
Go to Top of Page

dotinf
Starting Member

6 Posts

Posted - 2010-02-15 : 21:39:00
Hi vijayisonly,

Thank you for your reply. I did what you said with the join and it worked.

Thank you very much for your help.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-02-16 : 10:02:25
Great. You're welcome
Go to Top of Page
   

- Advertisement -