0

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.
dogbane
  • 266,786
  • 75
  • 396
  • 414
Yves
  • 12,059
  • 15
  • 53
  • 57

2 Answers2

1

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
  • 92,005
  • 12
  • 114
  • 115
  • Hi Eric, I only need results: THIS WEEK NUMBER. It's correct syntax but the results are: WEEK NUMBER DATA for the whole year. – Yves Aug 18 '09 at 17:28
  • Eric, I understand your logic; you are doing hard code. I need to use: GETDATE() – Yves Aug 18 '09 at 17:30
  • @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 Aug 18 '09 at 17:31
  • you are right - I am doing validation. Can you help me on this? – Yves Aug 18 '09 at 17:32
0

This looks good to me.

tw39124
  • 9,103
  • 2
  • 20
  • 14