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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Creating weeks of the month

Author  Topic 

Mattn
Starting Member

2 Posts

Posted - 2006-11-14 : 20:02:38
I am trying to automaticaly code so that I can get outstanding quantitys per week per month for an entire year
Here is the code I have written but it will not work over a Year-end

IF ( [BPW_Ewos_Canada].[Sales].[Invoice date]>= ( year(getdate())*10000 + month(getdate())*100 + day(0))and [BPW_Ewos_Canada].[Sales].[Invoice date] <= ( year(getdate())*10000 + month(getdate())*100 + day(_add_days(getdate(), -7 ))))THEN ( [BPW_Ewos_Canada].[Sales].[Invoiced quantity - basic U/M]/1000 ) ELSE ( 0 )

Because there is no week function with MS SQL that I can see any ideas would be great

I am looking to get the following

Jan 2006
Week 1 contains Jan 1 -7
Week 2 contains Jan 8 - 14
Week 3 contains Jan 15 - 21
Week 4 contains Jan 22 - 28
Week 5 contains Jan 29 - Feb 4

Feb 2006
Week 1 contains Feb 1 - 7
Week 2 contains Feb 8 - 14
Week 3 contains Feb 15 - 21
Week 4 contains Feb 22 - 28

And so on

everything is dependant on the month chosen the number of weeks that show up. So the most weeks you may have will be 5. Not the 1 - 52 that show with datepart() or dateDiff()


matt

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-14 : 20:59:31
"Because there is no week function with MS SQL"
This will gives you the week no of the year.

select datepart(week, getdate())



KH

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-11-14 : 21:26:07
What is your exact definition of “week”?

That is something that varies from one organization to the next. For example, many organizations use ISO week.






CODO ERGO SUM
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-15 : 12:20:49
check out week related function here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=64762


KH

Go to Top of Page
   

- Advertisement -