need to merge two queries result

Posted by Vanchi050585 under Sql Server on 9/8/2010 | Points: 10 | Views : 3768 | Status : [Member] | Replies : 5
hi friends,

i want to merge below two queries:
first queries result then 2nd queries result

select TransactionNo,CustomerName,CustID,InstallmentDates,RepayAmt from tblInstallmentDates where TransactionNo='4' and CustID='24'

select Amount as RecdAmt,Date as RecdDate,ReceivedBy from tblWeeklyRecieptsInfo where TransactionNo='4' and CusId='24'



Thanks

Thanks
tvn



Responses

Posted by: Peermohamedmydeen on: 9/8/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Try this..


select ID.TransactionNo,ID.CustomerName,ID.CustID,ID.InstallmentDates,ID.RepayAmt, WR.Amount as RecdAmt,WR.Date as RecdDate,WR.ReceivedBy
from tblInstallmentDates as ID left join tblWeeklyRecieptsInfo as WR on ID.TransactionNo = WR.TransactionNo and ID.CusId = WR.CusId
where ID.TransactionNo='4' and ID.CustID='24'



Thanks and Regards
PMM :)

Vanchi050585, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 9/8/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Vanchi,

Just change into...

select A.TransactionNo,A.CustomerName,A.CustID,A.InstallmentDates,A.RepayAmt, 

B.Amount as RecdAmt,B.Date as RecdDate,B.ReceivedBy from tblInstallmentDates A,tblWeeklyRecieptsInfo B where A.TransactionNo='4' and A.CustID='24'
and A.TransactionNo=B.TransactionNo and A.CustID=B.CusId

Try this query if any doubt ask to me.

Cheers :)

Thanks,
T.Saravanan

Vanchi050585, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: PandianS on: 9/8/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi
Try this...


SELECT D.TransactionNo,
D.CustomerName,
D.CustID,
D.InstallmentDates,
D.RepayAmt,
I.Amount AS RecdAmt,
I.[Date] AS RecdDate,
I.ReceivedBy
FROM tblInstallmentDates D(NOLOCK) JOIN tblWeeklyRecieptsInfo I(NOLOCK)
ON (D.TransactionNo = I.TransactionNo AND D.CustID = I.CusId)
WHERE D.TransactionNo='4' AND D.CustID='24'


Cheers

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Vanchi050585, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 9/14/2010 [Member] Starter | Points: 25

Up
0
Down
Hi,
To join both quries you need UNION ALL as follows

select TransactionNo,CustomerName,CustID,InstallmentDates,RepayAmt from tblInstallmentDates where TransactionNo='4' and CustID='24' 

UNION ALL
select Amount as RecdAmt,Date as RecdDate,ReceivedBy from tblWeeklyRecieptsInfo where TransactionNo='4' and CusId='24'



Syed Shakeer Hussain

Vanchi050585, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: PandianS on: 9/16/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Syedshakeer,

Do you think the query you have posted will work Properly ???? Kindly Check!

select TransactionNo,CustomerName,CustID,InstallmentDates,RepayAmt from tblInstallmentDates where TransactionNo='4' and CustID='24'
UNION ALL
select Amount as RecdAmt,Date as RecdDate,ReceivedBy from tblWeeklyRecieptsInfo where TransactionNo='4' and CusId='24'

Cheers

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Vanchi050585, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response