Solved

How do I joint 2 simple SQL statements?

Posted on 2008-06-11
3
210 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
In SQL Server 2016, can we configure MASKing rules that applies for application level users ? 12 65
sql help 8 58
SQL Server 2012 r2 - Varible Table 3 32
SQL query and VBA 5 46
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…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

837 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