For some reason, the following gives me an error:
DECLARE @Param1 DATETIME2(3)=...; -- Assign some date/time
DECLARE @Param2 DATETIME;
DECLARE @Param3 DATETIME;
EXEC dbo.SomeStoredProc CONVERT(DATE, @Param1), @Param2 output, @Param3 output;
The output is a compilation failure:
Msg 156, Level 15, State 1, Line 5 Incorrect syntax near the keyword
‘CONVERT’.
Changing it to the following fixes the problem:
DECLARE @Param1 DATETIME2(3)=...; -- Assign some date/time
DECLARE @Param2 DATETIME;
DECLARE @Param3 DATETIME;
DECLARE @TempDate DATE=CONVERT(DATE,@Param1);
EXEC dbo.SomeStoredProc @TempDate, @Param2 output, @Param3 output;
Stored procedure parameters can’t contain expressions, they have to be constant values or
@variables. In your example,CONVERT()is an expression and is therefore not allowed.The same is true for default parameter values.