Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.Net - SQL Query Help

Posted on 2013-12-20
8
Medium Priority
?
233 Views
Last Modified: 2014-01-02
Good Day Experts!

I am not sure if I can do all the required "checks" in one query.  Hopefully you can help me find out if it is possible and how to do it.

Status table:
     - InvoiceNumber
     - TrackingNumber
     - ServiceFailure
     - SFRejected
     - DatePC

DWINonPay table:
     - InvoiceNumber
     - TrackingNumber
     - DateImported

Select * from Status with the following requirements:

Requirements:
     - Status.ServiceFailure = 1
     AND
     - Status.SFRejected = 1
     AND
     - (DW1NonPay InvoiceNumber/TrackingNumber from Status not found
        OR
       (DW1NonPay InvoiceNumber/TrackingNumber from Status found but
        DW1NonPay.DateImported > Status.DatePC)

Please ask questions and let me know your opinions.

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39731926
Not sure what you are trying to check?  Do the requirements mentioned above reflect individual checks, or are you simply trying to identify all the records across the two tables that satisfy all of those requirements, in a single query?
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 1000 total points
ID: 39731937
Try this:
SELECT t1.* 
    FROM Status t1
         LEFT JOIN DWINonPay t2 ON t1.InvoiceNumber = t2.InvoiceNumber 
              AND t1.TrackingNumber = t2.TrackingNumber
    WHERE 
    (
        t1.ServiceFailure = 1
        AND t1.SFRejected = 1
        AND
        (
             t2.DateImported IS NULL
             OR t2.DateImported > t1.DatePC
        )
    )

Open in new window

0
 

Author Comment

by:Jimbo99999
ID: 39731976
Hello fyed:

Your second part is what I am trying to do...I am just not that good at complicated SQL query "stuff":

"trying to identify all the records across the two tables that satisfy all of those requirements in a single query"

Thanks,
jimbo99999
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Jimbo99999
ID: 39731986
Hello carl_tawn:

Can you help me understand your query as I am not very good at complicated SQL query "stuff"?  Is it adding subsets of data together from both tables?

Thanks,
jimbo99999
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39731989
No, it is doing a LEFT JOIN between the tables, so it will join but return NULL where there is no match. The rest is just applying the rules you listed, the brackets group the logic.
0
 

Author Comment

by:Jimbo99999
ID: 39732007
Excellent...thanks for the exlain.  I will try it now.
0
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 1000 total points
ID: 39732016
SELECT S.InvoiceNumber,
      S.TrackingNumber,
   S.ServiceFailure,
   S.SFRejected,
   S.DatePC
FROM Status AS S
LEFT OUTER JOIN DWINonPay AS D
      ON S.InvoiceNumber = D.InvoiceNumber
      AND S.TrackingNumber = D.TrackingNumber
WHERE S.ServiceFailure = 1
   AND S.SFRejected = 1
   AND (D.InvoiceNumber IS NULL OR D.DateImported > S.DatePC)
0
 

Author Comment

by:Jimbo99999
ID: 39736173
I am finally able to get back to this project and have received known data samples to test the query and logic in my code to.

Thanks for the responses and I will try them,
jimbo99999
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

610 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