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)
 How to show results of two query side by side

Author  Topic 

cyberpd
Yak Posting Veteran

60 Posts

Posted - 2006-11-14 : 01:24:11
I have written two queries and now i want to show the result of both of them side by side, let me explain...
The following is the first query..

[1] SELECT DISTINCT TRP.ATTRIBUTES,TD.TD_FIN_ID
FROM TRN_HEADER TH,TRN_CHANNEL TC,MST_PARTY MP,TRN_DETAILS TD,TRN_READYPRODUCT TRP
WHERE TH_DATE='14-NOV-06'
AND TH_MA_ID=10 AND TH.TH_CI_ID=TC.CI_ID AND TH.TH_TO=MP.PARTYID AND TH.TH_ID=TD.TD_TH_ID AND TRP.PRODID=TD.TD_FIN_ID

This is the second query...

[2] SELECT MP.PARTYNAME,TD.TD_PLANNED_DATE
FROM TRN_HEADER TH,MST_PARTY MP,TRN_DETAILS TD,TRN_READYPRODUCT TRP
WHERE TH.TH_MA_ID=1 AND TH.TH_FROM=MP.PARTYID AND TH.TH_CI_ID IN (54,55,82) AND TH.TH_ID=TD.TD_TH_ID AND
TD.TD_MC_ID=TRP.PRODID

Now i want the result set to look like this..
The two fields from the first query will be the first two columns and the two fields from the second query will be the last two columns

TRP.ATTRIBUTES, TD.TD_FIN_ID, MP.PARTYNAME, TD.TD_PLANNED_DATE

plz help.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-14 : 01:26:25
What is the relationship between the result of 2 queries ?

You can use derived table to join the results


KH

Go to Top of Page

cyberpd
Yak Posting Veteran

60 Posts

Posted - 2006-11-14 : 01:50:49
I want to join the two queries and get the result in the way I have shown. firstly , I thought about cartesian product, but the problem is the WHERE clause. In one query MA_ID=10 and in another query MA_ID=1. with this filtering I can't get the desired resultset.

Could you explain, how can i create derived table or how to use it...

I can solve my problem easily by creating a temporary table but I want a better solution...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-14 : 01:53:41
[code]
select q1.ATTRIBUTES, q1.TD_FIN_ID, q2.PARTYNAME, q2.TD_PLANNED_DATE
from
(

SELECT DISTINCT TRP.ATTRIBUTES,TD.TD_FIN_ID
FROM TRN_HEADER TH,TRN_CHANNEL TC,MST_PARTY MP,TRN_DETAILS TD,TRN_READYPRODUCT TRP
WHERE TH_DATE='14-NOV-06'
AND TH_MA_ID=10 AND TH.TH_CI_ID=TC.CI_ID AND TH.TH_TO=MP.PARTYID AND TH.TH_ID=TD.TD_TH_ID AND TRP.PRODID=TD.TD_FIN_ID

) q1
CROSS JOIN -- or INNER JOIN depending on your requirement
(

SELECT MP.PARTYNAME,TD.TD_PLANNED_DATE
FROM TRN_HEADER TH,MST_PARTY MP,TRN_DETAILS TD,TRN_READYPRODUCT TRP
WHERE TH.TH_MA_ID=1 AND TH.TH_FROM=MP.PARTYID AND TH.TH_CI_ID IN (54,55,82) AND TH.TH_ID=TD.TD_TH_ID AND
TD.TD_MC_ID=TRP.PRODID

) q2
[/code]


KH

Go to Top of Page
   

- Advertisement -