Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Basic Sql query please help im new

Author  Topic 

emdavies82
Starting Member

2 Posts

Posted - 2011-06-07 : 06:14:34
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

Ifor
Aged Yak Warrior

700 Posts

Posted - 2011-06-07 : 07:40:18
[code]
WHERE Department = '971'
-- this may enable use of index - google SARGABLE
AND Tax_Year BETWEEN '2009' AND '2010'
-- assuming Tax_Year and Tax_Period are stings as the quotes indicate
AND Tax_Year + Tax_Period BETWEEN '200941' AND '201040'
-- if Tax_Year and Tax_Period are integers
-- AND Tax_Year * 100 + Tax_Period BETWEEN 200941 AND 201040
[/code]
Go to Top of Page
   

- Advertisement -