I have written this query; I need help in assigning variable; which is coming from other query, How can I do that.
How can I combine them together?
Query 1
Select SUM(Credit)
FROM(SELECT TOP 1 Credit
FROM (SELECT DISTINCT TOP 2 Ref, Credit, PaymentID
FROM Payment where Ref = '????' AND PaymentID <= '????'
ORDER BY PaymentID DESC)
a ORDER BY PaymentID)
b
Query 2
Select Ref, PaymentID
From Payment
Where PaymentDate = '2012-09-23'
SO I need Ref and PaymentID of Query 2 and use as variable in Query 1
By using a join