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 7184459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:12:23+00:00 2026-05-28T18:12:23+00:00

FYI – this query runs from excel. i have prompt fields to set date

  • 0

FYI – this query runs from excel. i have prompt fields to set date range.

here is the original working query i got from someone:

SELECT 
   SalesInvoiceItems.FreeTextItem, SalesInvoiceItems.Product,   
   SalesInvoiceItems.ItemDescription, SalesInvoiceItems.Quantity, 
   SalesInvoiceItems.ItemValue, Customers.CustomerId, Customers.CustomerName, 
   SalesInvoices.SalesInvoiceId, SalesInvoices.EffectiveDate, Countries.CountryId, 
   SalesInvoiceItems.ItemType
FROM 
   Winman.dbo.Countries Countries, Winman.dbo.Customers Customers, 
   Winman.dbo.Products Products, Winman.dbo.SalesInvoiceItems SalesInvoiceItems, 
   Winman.dbo.SalesInvoices SalesInvoices
WHERE 
    Customers.Customer = SalesInvoices.Customer 
    AND SalesInvoiceItems.SalesInvoice = SalesInvoices.SalesInvoice 
    AND Customers.Country = Countries.Country 
    AND ((SalesInvoices.SystemType='F') 
    AND (SalesInvoiceItems.ItemType<>'T') 
    AND (SalesInvoices.EffectiveDate>=? And SalesInvoices.EffectiveDate<=?) 
    AND (SalesInvoiceItems.ItemValue<>$0))
ORDER BY 
    SalesInvoiceItems.Quantity DESC

Important bit here is ItemType (it can only be T, wich is excluded, P – for products and N – for free text items)

I needed to add table Products, to retrieve ProductID. Obviously adding below code in WHERE clause:

AND Products.Product = SalesInvoiceItems.Product 

will fail to bring up any free text item, as the aren’t products.

So I rewrote query with JOINs hoping that will solve my problem (bringing up both P and N type of entries):

SELECT 
    Products.ProductId, 
    SalesInvoiceItems.FreeTextItem, 
    SalesInvoiceItems.Product, 
    SalesInvoiceItems.ItemDescription, 
    SalesInvoiceItems.Quantity, 
    SalesInvoiceItems.ItemValue, 
    Customers.CustomerId, 
    Customers.CustomerName, 
    SalesInvoices.SalesInvoiceId, 
    SalesInvoices.EffectiveDate, 
    Countries.CountryId, 
    SalesInvoiceItems.ItemType
FROM 
    Winman.dbo.SalesInvoiceItems AS SalesInvoiceItems 
INNER JOIN 
    Winman.dbo.Products AS Products ON Products.Product = SalesInvoiceItems.Product  
INNER JOIN 
    Winman.dbo.SalesInvoices AS SalesInvoices ON SalesInvoices.SalesInvoice= SalesInvoiceItems.SalesInvoice
INNER JOIN 
    Winman.dbo.Customers AS Customers ON Customers.Customer = SalesInvoices.Customer 
INNER JOIN 
    Winman.dbo.Countries AS Countries ON  Countries.Country = Customers.Country 
WHERE 
    ((SalesInvoices.SystemType='F') 
     AND (SalesInvoiceItems.ItemType<>'T') 
     AND (SalesInvoices.EffectiveDate >= ? And SalesInvoices.EffectiveDate <= ?) 
     AND (SalesInvoiceItems.ItemValue <> $0)
    )
ORDER BY 
    SalesInvoiceItems.Quantity DESC

but this still acts as AND – which ignores free text items! I’m obviously missing something.. how can I bring both products and free text items, despite that free text items don’t have ProductID ?

  • 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-05-28T18:12:24+00:00Added an answer on May 28, 2026 at 6:12 pm

    Your old query is using old style JOIN syntax. It is a good thing to completely abandon this implicit (inner) joining in favor of explicit joining.

    When using explicit joins, you now have a choice between INNER and OUTER joins (ref. MSDN).

    Inner joins return rows only when there is at least one row from both
    tables that matches the join condition. Inner joins eliminate the rows
    that do not match with a row from the other table. Outer joins,
    however, return all rows from at least one of the tables or views

    mentioned in the FROM clause, as long as those rows meet any WHERE or
    HAVING search conditions.

    So in response to your question, change your INNER JOINs to LEFT JOINs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

FYI This is homework. I have to build a Java Chat server. I have
FYI: I have edited this significantly since my first edition. This simulation has been
I have a form for quick product entry. (FYI, I have the form set
FYI, There is some overlap in the initial description of this question with a
Ok, so I have the code below (Objective-C FYI) and I was wondering if
* FYI: I'm not using Adsense and this is not against my TOS... I
This code trims whitespace, (fyi: it's credited to be very fast) function wSpaceTrim(s){ var
I have a single dimensional array of floating point values (c# doubles FYI) and
This should be fairly simple; i'm pretty sure I've just not understood it. FYI,
Assume you do a git push remote_a from remote_b . Is this the same

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.