Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:15:09+00:00 2026-06-18T00:15:09+00:00

I have a query that pulls a lot of the information I need filtered

  • 0

I have a query that pulls a lot of the information I need filtered by multiple WHERE clauses. However, I don’t want the my main table (inv_data in this case) to be affected by all the WHERE clauses. Is there any way to choose which tables get affected by which WHERE?

Here’s my current query:

$query_ats = "SELECT
                i.prod_cd as product,
                i.descrip as description,
                i.in_stock as current_stock, 
                SUM(p.log_qty) as purchase_order,
                SUM(l.order_qty + e.order_qty) as total_so
            from
                inv_data as i
                inner join plog as p
                    on i.prod_cd = p.prod_cd
                inner join ord_log as l
                    on i.prod_cd = l.prod_cd
                inner join ediordlg as e
                    on i.prod_cd = e.prod_cd
            where
                i.class_cd = 'ALG7'
            AND 
            dateadd(day, p.EST_DT, '18001228') BETWEEN getdate() and dateadd(day, 14, getdate())
            AND 
            dateadd(day, l.SHIP_DT, '18001228') BETWEEN getdate() and dateadd(day, 14, getdate())
            AND 
            dateadd(day, e.SHIP_DT, '18001228') BETWEEN getdate() and dateadd(day, 14, getdate())
            group by
                i.prod_cd,
                i.descrip,
                i.in_stock,
            order by
                i.prod_cd ASC";

Table i (inv_data) is my main table that I do not want affected by any of the dateadd clauses.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:15:10+00:00Added an answer on June 18, 2026 at 12:15 am

    Left outer join the conditions and move the conditions to the on clause:

    SELECT i.prod_cd as product,
           i.descrip as description,
           i.in_stock as current_stock, 
           SUM(p.log_qty) as purchase_order,
           SUM(l.order_qty + e.order_qty) as total_so
    from inv_data i left outer join
         plog p
         on i.prod_cd = p.prod_cd and
            dateadd(day, p.EST_DT, '18001228') BETWEEN getdate() and dateadd(day, 14, getdate())
         left outer join
         ord_log l
         on i.prod_cd = l.prod_cd and
            dateadd(day, l.SHIP_DT, '18001228') BETWEEN getdate() and dateadd(day, 14, getdate()) 
         left outer join
         ediordlg e
         on i.prod_cd = e.prod_cd and
            dateadd(day, e.SHIP_DT, '18001228') BETWEEN getdate() and dateadd(day, 14, getdate())
    where i.class_cd = 'ALG7'
    group by i.prod_cd, i.descrip, i.in_stock,
    order by i.prod_cd ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that pulls values from multiple tables. I want to order
I have a LINQ to ENTITY query that pulls from a table, but I
So I have this query that pulls from my links and votes table and
I'm making a query that pulls a lot of data from a sql table.
I have a query I need to perform on a table that is roughly
I have a LINQ query that pulls down some information based on certain criteria
I have a query that pulls up questions from one table and answers from
I have a query that pulls back a user's feed which is essentially all
I have this SQL Query that pulls data from 3 tables. I am unable
I have an Excel spreadsheet that uses a TFS query to pull information on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.