Link to home
Create AccountLog in
Avatar of deakie
deakie

asked on

How do I joint 2 simple SQL statements?

I have two simple sql statements that I need to join...how would I do that?
P.SEQUENCE is the same as D.SEQUENCE
AND P.BILL is the same as M.IDENT

Here are the statements:
SELECT P.BILL, P.SEQUENCE, P.LOCATION, P.TYPE
      FROM dbo.POLICY P
      WHERE P.BILL = '24680'

SELECT M.IDENT, D.SEQUENCE, I.IDENT, S.IDENT, D.*
      FROM BILL M (NOLOCK),
            INVOICE I ,
            STATUS S ,
            STATUSDETAIL D
      WHERE M.IDENT = '24680'
            AND I.IDENT = '13579'
            AND I.BILL = M.IDENT
            AND S.INVOICE = I.IDENT
            AND D.STATUS = S.IDENT
Avatar of dragos_craciun
dragos_craciun
Flag of Romania image

SELECT M.IDENT, D.SEQUENCE, I.IDENT, S.IDENT, D.*
      FROM BILL M (NOLOCK),
            INVOICE I ,
            STATUS S ,
            STATUSDETAIL D,
            dbo.POLICY P
      WHERE M.IDENT = '24680'
            AND I.IDENT = '13579'
            AND I.BILL = M.IDENT
            AND S.INVOICE = I.IDENT
            AND D.STATUS = S.IDENT
            AND P.SEQUENCE = D.SEQUENCE AND P.BILL = M.IDENT
ASKER CERTIFIED SOLUTION
Avatar of dragos_craciun
dragos_craciun
Flag of Romania image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of deakie
deakie

ASKER

Thanks so much for your quick response....of course your solution works exactly as expected and the results are what I needed!!