Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

function or procedure for dynamic generation of weeks for given month period. Expand / Collapse
Author
Message
Posted Monday, May 11, 2009 4:10 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, December 8, 2010 7:22 AM
Points: 46, Visits: 107
function or procedure for dynamic generation of weeks for given month period. lets take if i give range march to may i have to get the number of weeks like mar1week(01/03-07/09)....May4wee(23/05-30/05) like that
Post #713955
Posted Monday, May 11, 2009 4:38 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 1:11 PM
Points: 7,019, Visits: 12,909
What have you tried so far?
Did you look into DATEADD/DATEPART functions in BOL?




Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #713967
Posted Monday, May 11, 2009 5:00 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, December 8, 2010 7:22 AM
Points: 46, Visits: 107
alter function [dbo].ReturnWeek() returns @testtable table (week int)
as
begin
declare @test int
declare @i int
select @test= datediff(wk,'2009-03-01',getdate()+1)
set @i=1
while(@i<=@test)
begin
insert into @testtable values (@i)
set @i=@i+1
end
return
end


this is what i have done so far
Post #713976
Posted Monday, May 11, 2009 2:10 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 1:11 PM
Points: 7,019, Visits: 12,909
Hi,

you should consider using a calendar table.

A start point would be the code posted by GSquared in http://www.sqlservercentral.com/Forums/FindPost513748.aspx




Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #714480
Posted Monday, May 11, 2009 2:38 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:28 PM
Points: 11,157, Visits: 12,897
I agree with the calendar table idea, but I still think you should answer the questions I posted on the other thread you started with the same question, http://www.sqlservercentral.com/Forums/Topic714216-9-1.aspx. Just post the answers here as everyone will be watching this thread now.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #714514
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse