tsql - SQL Server returns unexpected week number -


i have orders in table , last order date of 2011 20th dec.

i'm using sql command calculate number of orders in given week:

select convert(varchar(3),datename(week,convert(datetime,order_date,103))) week,    count(1) orders  order_table  datename(year,convert(datetime,order_date,103)) = '2011'  group convert(varchar(3),datename(week,convert(datetime,order_date,103)))  order week asc 

it returns me of following results:

week | orders   41   | 42   42   | 110   43   | 115   ... ...   51   | 155   52   | 15 

the trouble is last order date of 2011 mentioned have 20th dec 2011, can't week 52 must week 51.

i've got other stats(off system, not sql server) giving me other figures , last week on 51 have no doubt correct. there's going queries if people looking both!

anyone have idea or know how sort this?

thanks,

the iso_week of 20th dec 2011 51. maybe need.

select datepart(iso_week, '2011-12-20') 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -