Issue:
You have a Transact SQL query, or a Stored Procedure, that needs a starting and ending date to capture the data. You want to give the user the ability to more accurately report data for the dates they require.
Resolution
/*Declare your variables*/
DECLARE @PerType int, @DtStart datetime, @DtParm int, @DtEnd datetime
/*Set values to variables*/
SELECT
@PerType = 0,
/*Period Types:
0 = Daily
1 = Weekly
2 = Monthly
3 = Quarterly
4 = Annually*/
@DtStart = '04/21/02',
@DtParm = 1
/*Calculate your end date*/
BEGIN
SELECT
IF @PerType = 0
@DtEnd = DateAdd(dd, @DtParm, @DtStart)
IF @PerType = 1
@DtEnd = DateAdd(wk, @DtParm, @DtStart)
IF @PerType = 2
@DtEnd = DateAdd(mm, @DtParm, @DtStart)
IF @PerType = 3
@DtEnd = DateAdd(qq, @DtParm, @DtStart)
IF @PerType = 4
@DtEnd = DateAdd(yy, @DtParm, @DtStart)
END
� 2002 Dan Herrera
These functions may be distributed freely, but please give credit where credit is due.
And if you feel you must give credit, or have a request for a custom function/macro,
please send me a note DataMasterFla
Sign Guestbook
View Guestbook
Back.