Consulting

Results 1 to 2 of 2

Thread: Get all results from where clause even value doestn exits.

  1. #1

    Get all results from where clause even value doestn exits.

    Hi I need your help for onle of my SQL query

    I have SQL query like this
    [vba]
    Select
    Week_Number As Week,
    Store_Number,
    Department,
    Sum(Sales) As Sales
    From
    Sales_Table
    Where Store_Number In (1,2,3)
    And Department In ('A','B','C')
    and Week_Number = 1

    Group By 1,2,3
    [/vba]

    This would give me the sales number only for the stores & department which are there in the where clause. If no sales available for the store 2 the that will not be shown in the output.

    But I need that store also on the result but with zero value, that is look data for all the stores in the where clause, if sales exists get the sales else get zero

    I have attached the excel sheet for which clearly shows my requirement.

    Thanks for your help
    Attached Files Attached Files

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Do you have a table for departments?

    If you did this would be a straightforward left join query.

    That would return all the records from the departments tables and only the matching records from the other tables.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •