SQL Server - Pass GetDate() in SP
Asked By farrukh on 01-Aug-12 06:29 AM
Hello Experts !
I want to run stored procedure for current date time its below i am correct ?
CREATE PROCEDURE PROC_NAME
@StartDate datetime = null ,
@EndDate datetime = null
AS
BEGIN
SET @StartDate = COALESCE(@StartDate, GETDATE())
SET @EndDate = COALESCE(@EndDate, GETDATE())
Update table1 set column_1=
(select column_2 from table2......)
From....
Where table1.start_datetime>=@StartDate
and table1.start_datetime<=@EndDate
Thanks
Hameed
Peter Bromberg replied to farrukh on 01-Aug-12 02:00 PM
YOU do not need to use the COALESCE function as getDate() already returns a DateTime object:
SET @StartDate = GETDATE()
SET @EndDate = GETDATE()
if you use COALESCE and the @StartDate is not null, that would then be the value that is assigned.