Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question on join statement

Status
Not open for further replies.

habesha

Programmer
Oct 30, 2006
68
0
0
US
I was trying to convert this query to ansi standard join statemet, but it is not giving the same record set waht did I miss

Code:
<html>
  <head>
    <title>query that should be converted</title>
  </head>
  <body>
    SELECT eae.EAE_SES_ID 
    FROM PHOENIX.EXPEDITED_ADVERSE_EVENTS EAE
    WHERE eae.EAE_SES_ID IN
     (SELECT SES.SES_ID 
      FROM voyager.STUDY_VERSION_SITES ses
      WHERE ses.SES_SVE_ID in 
	(SELECT sve.sve_id 
         from voyager.STUDY_VERSIONS sve
         WHERE sve.sve_stu_id in
	 (SELECT sso.sso_stu_id 
	  FROM  voyager.STUDY_STAKEHOLDER_ORGANIZATIONS sso
	  WHERE (@VAR IS NULL or sso.sso_oty_id =@VAR)	 
	  )
	)
      )
  </body>

  <head>
    <title>ansi-standard join statement</title>
  </head>
  <body>
    SELECT eae.EAE_SES_ID 
    FROM PHOENIX.EXPEDITED_ADVERSE_EVENTS EAE INNER JOIN 
    voyager.STUDY_VERSION_SITES ses 
    ON SES.SES_ID = eae.EAE_SES_ID
    INNER JOIN voyager.STUDY_VERSIONS sve
    ON ses.SES_SVE_ID = sve.sve_id
    INNER JOIN voyager.STUDY_STAKEHOLDER_ORGANIZATIONS sso
    ON sve.sve_stu_id = sso.sso_stu_id 
    WHERE (@VAR IS NULL or sso.sso_oty_id =@VAR)  
  </body>
</html>
 
Mind if I ask why the html markup is in the code window? The point of that window is to make things easier to read...


As to your question, how is the recordset different? If it is returning more records, odds are you have a duplicate in one of the rows you are joining on.

Good Luck,

Alex

Ignorance of certain subjects is a great part of wisdom
 
it is returnig more records
there ia a duplicate value on sve.sve_stu_id, sso.sso_stu_id, ses.SES_SVE_ID, eae.EAE_SES_ID

what should my could look like in ansi-standard join statement
 
Code:
SELECT eae.EAE_SES_ID
       FROM PHOENIX.EXPEDITED_ADVERSE_EVENTS EAE
       INNER JOIN (SELECT SES.SES_ID, ses.SES_SVE_ID
                          FROM voyager.STUDY_VERSION_SITES ses
                          INNER JOIN (SELECT sve.sve_id, sve.sve_stu_id
                                             from voyager.STUDY_VERSIONS sve
                                             INNER JOIN (SELECT sso.sso_stu_id
                                                               FROM  voyager.STUDY_STAKEHOLDER_ORGANIZATIONS sso
                                                               WHERE (@VAR IS NULL or sso.sso_oty_id =@VAR)) Sso
                                              ON sve.sve_stu_id = Sso.sso_stu_id) Sve
                          ON ses.SES_SVE_ID = sve.sve_id) Ses
       ON EAE.EAE_SES_ID = SES.SES_ID

Not tested at all

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top