Re: Pulling data that could be in one of 2 tables



Matt,

I believe that you are looking for a UNION, such as:

SELECT OriginalOrderNum, Column1, Column2, Column3
FROM Table1
WHERE ...
UNION ALL
SELECT OriginalOrderNum, Column1, Column2, Column3
FROM Table2
WHERE OriginalOrderNum NOT IN
(SELECT OriginalOrderNum FROM Table1)
AND ...

Read about UNION and UNION ALL since they are not identical. The above
query can then be used with whatever other reporting criteria you have.

RLF

"Matt M" <MattM@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:84AF08D4-F845-4412-A7BC-A429110F736E@xxxxxxxxxxxxxxxx
Note: I am using this to create a report with SRS

I need to pull some data that could possibly be sitting in one of two
tables. Table1 is the "Current" table that holds Orders that have not
shipped
yet. Once all of items on the Order have shipped the Order moves to Table2
and an invoice is created. However, there are times where only part of the
order ships so there is an Invoice placed in Table2 but the Order still
remains in Table1. The invoice also has a field that always points to the
original Order number. And Table1 and Table2 have the same exact fields as
each other.

Here is what I need to do. I need to go through all of the Invoices in
Table2 for a certain time period, and Group them by Order Type (Which is
stored in the Order record). The problem is, if the order does not exist
in
Table 2 yet, I need to get the Order type from Table1. I am sure how
exactly
to do this. Is it something in the SQL query like an If or Case Statement?
Then I though about looking into Stored Procedures but I dont know much
about
using them, especially in SRS so I would need some pointers.

Maybe something like:

Select *, If(Table1.OriginalOrderNum in Table2 then Table2.OrdType else
Table1.Ordtype)
From Table1
Where....

I know that is totally incorrect but I hope it clarifies things.

Once I have that squared away, I just need to sum up the Invoice amounts
in
each Order Type Group, but that should be easy enough if I can figure out
the
first part.

Was that clear enough? Let me know if you need any clarification.


.



Relevant Pages

  • Re: Pulling data that could be in one of 2 tables
    ... value in the OrderType column do you need to look in Table1. ... Original Order with each Invoices Original Order Number in Table2 first. ... I need to be able grab the Order Type from the Order and the Invoice ...
    (microsoft.public.sqlserver.mseq)
  • Re: Pulling data that could be in one of 2 tables
    ... Invoices from Table2 and find the corresponding DOCID for its Original Order. ... Invoice amount from table2 so I can add it up in SRS. ... value in the OrderType column do you need to look in Table1. ...
    (microsoft.public.sqlserver.mseq)
  • Re: Pulling data that could be in one of 2 tables
    ... Table1. ... The Invoices I am looking up are in Table2. ... Original Order with each Invoices Original Order Number in Table2 first. ... I need to be able grab the Order Type from the Order and the Invoice ...
    (microsoft.public.sqlserver.mseq)
  • Re: Pulling data that could be in one of 2 tables
    ... value in the OrderType column do you need to look in Table1. ... Original Order with each Invoices Original Order Number in Table2 first. ... I need to be able grab the Order Type from the Order and the Invoice ...
    (microsoft.public.sqlserver.mseq)
  • Re: Tricky Visual Basic Code help...
    ... moves the current record into a new record in table2. ... this with a little VBA code and a couple custom queries. ... Set a "pushFlag" column in the record in table1 to a specific ... If a duplicate is not found, ...
    (microsoft.public.access.formscoding)