September 17, 2008 at 9:13 am
Hi,
I am calling a procedure that requires two dates sets to run Eg exec my_proc '08/08/08/ , '14/08/08'.
Would it be possible to write into the stored procedure that the default dates would always be between today and today -7?. This would remove the requirement enter the dates when calling the procedure.
Any help would be most appreciated.
September 17, 2008 at 9:30 am
CREATE FUNCTION [dbo].[TRUNC]
(
@datInDATETIME
)
RETURNS DATETIME
AS
BEGIN
RETURN CAST(FLOOR(CAST( @datIn AS float))AS datetime)
END
CREATE PROCEDURE spMyProc
(
@datStartDATETIME= NULL
)
AS
DECLARE @datEndDATETIME
SELECT @datStart = COALESCE(@datStart, dbo.TRUNC(GETDATE()))
SELECT @datEnd = DATEADD(Day, -7, @datStart)
etc ....
September 17, 2008 at 8:01 pm
You might want to consider using 4 digit years and, possibly, a date format where the month and day cannot be confused... for example, is 06/07/2008 June 7th or July 6th?
--Jeff Moden
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply