Basic SQL help please sorry new

  • Got simple query:

    SELECT Department, Tax_Year, Tax_Period, Total_Bill, Total_Hours, Purchase_Order_Number

    FROM Timesheets

    WHERE (Department = '971') AND (Tax_Year = '2010') AND (Tax_Period > '41')

    I want to change this so it does a total_bill for each different Purchase_Order_Number Number for all timesheets between Tax_Week 41 and Tax_Year 2009

    and Tax_Week 40 and Tax_Year 2010 for Department 971

    When i do it i am only getting data > tax week 41 and less than week 40. It mjisses out tax year 1,2,3 ext for the higher year.

    Sorry this is so basic but teaching myself.

    Thanks for any help

  • You can try this to see if you filter the correct data:

    SELECT

    Department,

    Tax_Year,

    Tax_Period,

    Total_Bill,

    Total_Hours,

    Purchase_Order_Number

    FROM Timesheets

    WHERE

    (Department = '971')

    AND (

    ( (Tax_Year = '2009') AND (Tax_Period >= '41') )

    OR

    ( (Tax_Year = '2010') AND (Tax_Period <= '40') )

    )

    Regards,

    Iulian

  • Thank you so much this works! I now need to sum the charge per purchase order number wish me luck!!!

  • I wish you luck! 🙂 post if you get stucked

    Regards,

    Iulian

  • Please don't cross post. It just wastes people's time and fragments replies

    No replies to this thread please. Direct replies to http://www.sqlservercentral.com/Forums/Topic1120833-391-1.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply