views:

109

answers:

2

I know how to look up this week number:

(SELECT DATEPART(wk, GETDATE()))

I need to know the syntax of getting the week number compare to another table: SYNTAX:

SELECT     THISWEEK  -- WEEK NUMBER DATA
FROM       dbo.DATETABLE
WHERE THISWEEK  = (DATEPART(wk, GETDATE()))  -- THIS IS THE PART I AM NOT SURE.
+1  A: 

That's the correct syntax. You have more than the necessary amount of parens, but it does no harm.

select distinct
    thisweek
from
    datetable
where
    thisweek = datepart(wk, getdate())

Is equivalent to saying:

select distinct
    thisweek
from
    datetable
where
    thisweek = 34 --8/18/09 is in the 34th week of 2009
Eric
Hi Eric, I only need results: THIS WEEK NUMBER. It's correct syntax but the results are: WEEK NUMBER DATA for the whole year.
Kombucha
Eric, I understand your logic; you are doing hard code. I need to use: GETDATE()
Kombucha
@Yonita: I changed the queries to only bring back the week number. Of course, this is really superfluous and too much overhead if you just need the week number, *unless* you're validating to make sure that week is in your date table.
Eric
you are right - I am doing validation. Can you help me on this?
Kombucha
+1 thank you Eric. :) DISTINCT!
Kombucha
A: 

This looks good to me.

Tom Woolfrey