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 2008 Forums
 Transact-SQL (2008)
 joining 2 queris

Author  Topic 

vipinjha
Starting Member

21 Posts

Posted - 2012-02-10 : 02:17:03
Dear Sir,
I have two queris both are working seperately
but when i ma join both am not getting the record from the second query

-------------QUERY1-------
SELECT TOP 5 TAM.ACID,
TAM.SOL_ID,TAM.DEPOSIT_AMOUNT,PYRH.PR_B2K_ID,TAB1.ACCT_NAME,
TAB1.FORACID,TAB1.SCHM_CODE,TAB1.SCHM_TYPE,tab4.FORACID,
TAM.MATURITY_DATE,TAB1.ACCT_OPN_DATE,PYRH.PR_B2K_TYPE,PYRH.PR_SRL_NUM
FROM TAM INNER JOIN PYRH ON TAM.ACID=PYRH.PR_B2K_ID
INNER JOIN (SELECT GAM.ACID,GAM.FORACID,GAM.ACCT_NAME,GAM.SCHM_CODE,GAM.SCHM_TYPE,GAM.ACCT_OPN_DATE FROM GAM)TAB1 ON TAB1.ACID=PYRH.PR_B2K_ID
LEFT JOIN (SELECT PYRH.PR_SRL_NUM,PYRD.ACID,GAM.FORACID
FROM PYRH INNER JOIN PYRD ON PYRH.PR_SRL_NUM=PYRD.PR_SRL_NUM INNER JOIN GAM ON GAM.ACID=PYRD.ACID) TAB2 ON TAB2.ACID=TAB1.ACID

left join (

-------------QUERY2------
SELECT
PYRH.PR_SRL_NUM,PYRD.ACID,tab3.FORACID FROM PYRH INNER JOIN PYRD ON PYRH.PR_SRL_NUM=PYRD.PR_SRL_NUM

INNER JOIN (SELECT GAM.FORACID,GAM.ACID FROM GAM)TAB3 ON TAB3.ACID=PYRD.ACID
)tab4 on tab4.ACID=TAB1.ACID


I want to take tab3.FORACID from query 2 .
plz advise the correct way .

Regards,
Vipin jha



Vipin jha

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-10 : 09:43:55
shows us some data from both queries and explain the issue. unless we see some data from these we cant understand what real issue and why you're not getting any result

also are there any filters applied to your query which is not shown above (WHERE clause)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -