Solved

How do I joint 2 simple SQL statements?

Posted on 2008-06-11
3
207 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:deakie
  • 2
3 Comments
 
LVL 6

Expert Comment

by:dragos_craciun
ID: 21759964
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
0
 
LVL 6

Accepted Solution

by:
dragos_craciun earned 500 total points
ID: 21759969
sorry, I forgot the columns:

SELECT M.IDENT, D.SEQUENCE, I.IDENT, S.IDENT, D.*, P.LOCATION, P.TYPE
      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
0
 

Author Closing Comment

by:deakie
ID: 31466146
Thanks so much for your quick response....of course your solution works exactly as expected and the results are what I needed!!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now