Also, keep in mind that you can always use GETDATE() within a stored procedure to grab the current Date/Time without having to pass it in. Also, keep in mind that you can always use GETDATE() within a stored procedure to grab the current Date/Time without having to pass it in.
SQL Server GETDATE() FunctionThe GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format.
You can't pass in a function call as an argument to your stored procedure. Instead use an intermediate variable:
DECLARE @tmp DATETIME
SET @tmp = GETDATE()
EXEC DisplayDate @tmp;
As Mitch Wheat mentioned you can't pass a function.
If in your case you should pass in a precalculated value or GETDATE() - you can use default value. For example, modify your stored procedure:
ALTER PROC DisplayDate
(
@DateVar DATETIME = NULL
) AS
BEGIN
set @DateVar=ISNULL(@DateVar,GETDATE())
--the SP stuff here
SELECT @DateVar
END
GO
And then try:
EXEC DisplayDate '2013-02-01 00:00:00.000'
EXEC DisplayDate
Remark: Here I supposed that NULL value is not in use for this parameter. If it is not your case - you can use another unused value, for example '1900-01-01 00:00:00.000'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With