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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL command issue

Status
Not open for further replies.

mlager

Programmer
Sep 1, 2006
74
US
Hello, I'm using MSSQL 2005. I have a sql query that looks like this (notice the *=):

CREATE VIEW RPS_PAYORGROUPING AS
SELECT A1.BILLNO,A1.MRN,
A1.PAYTYPE AS PAYTYPE1,
A1.PAYOR AS PAYOR1,
A2.PAYTYPE AS PAYTYPE2,
A2.PAYOR AS PAYOR2
FROM BILLED A1, BILLED A2
WHERE A1.BILLNO *= A2.BILLNO AND A1.DESCRIPT = 'INV' AND A2.DESCRIPT = '2ND'

When I create this as a view, MSSQL converts it to:

SELECT A1.BILLNO, A1.MRN, A1.PAYTYPE AS PAYTYPE1, A1.PAYOR AS PAYOR1, A2.PAYTYPE AS PAYTYPE2, A2.PAYOR AS PAYOR2
FROM dbo.BILLED AS A1 LEFT OUTER JOIN
dbo.BILLED AS A2 ON A1.BILLNO = A2.BILLNO
WHERE (A1.DESCRIPT = 'INV') AND (A2.DESCRIPT = '2ND')

The second query doesn't not include the NULL entries as in query 1. How can I get the first query converted so it shows records that don't exist in the second aliased table. If this doesn't make sense, let me know. Thanks for any help!

 
Hi mlager,

Looks like the second criteria on a2.descript is invalidating the outer join. You need to change this to something like:


SELECT A1.BILLNO, A1.MRN, A1.PAYTYPE AS PAYTYPE1, A1.PAYOR AS PAYOR1, A2.PAYTYPE AS PAYTYPE2, A2.PAYOR AS PAYOR2
FROM dbo.BILLED AS A1 LEFT OUTER JOIN
dbo.BILLED AS A2 ON A1.BILLNO = A2.BILLNO
AND A2.DESCRIPT = '2ND'
WHERE (A1.DESCRIPT = 'INV')

...and hopefully that should do it.

 
Fantastic, I appreciate your help on this!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top