Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about Datepart

Status
Not open for further replies.

nedrob

MIS
Jun 11, 2001
7
US
I am trying to create a query to return the Number of hours worked in the current week. However, I have two years of data and for some reason this query is pulling data from last year and not the current year. I'm new at this and am sure I'm probably overlooking the obvious. Thanks for any input you might have.
Ron

P.S. 'Pay_Ending_Date' is a 'DateTime Datatype


'Hrs' = SUM(CASE WHEN DATEPART(WW, CURRENT_TIMESTAMP) = DATEPART(WW, Pay_Ending_Date) THEN [Bill Hours] ELSE '0' END)
 
Maybe I'm missing something (not unlikely) but it seems like you're taking a more complicated route than need be. How about:

[tt]'Hrs' = SUM([Bill Hours])
...
where DATEPART(WW, CURRENT_TIMESTAMP) =
DATEPART(WW, Pay_Ending_Date)
and DATEPART(YY, CURRENT_TIMESTAMP) =
DATEPART(YY, Pay_Ending_Date)

[/tt]

Robert Bradley
Support operation moo!
Visit the OpCow page to help in this cause
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top