SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Find number of weeks between dates
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Patyk
Starting Member

44 Posts

Posted - 01/07/2014 :  14:43:01  Show Profile  Reply with Quote
I need to create a store procedure to open a table containing
Fiscal Year, Fiscal Month, Start Date, End Date, Number of Weeks, calculate number of weeks and insert this number into Number Of Weeks column?

All is populated except the number of weeks


Thanks

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 01/07/2014 :  15:16:52  Show Profile  Reply with Quote
first thought is use date datediff function:

DATEDIFF(week, [Start Date], [End Date])

A general principal is not to store a value that can be derived from other values in the same row. In other words can you just use this function whenever you want to see the value and not store it in the table? An alternative is to define the column as a "computed column" using that function as its definition.

Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/08/2014 :  05:52:24  Show Profile  Reply with Quote
quote:
Originally posted by Patyk

I need to create a store procedure to open a table containing
Fiscal Year, Fiscal Month, Start Date, End Date, Number of Weeks, calculate number of weeks and insert this number into Number Of Weeks column?

All is populated except the number of weeks


Thanks


what according to you represents a week? does it coincide with iso week?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000