Why am I getting an error using CONVERT on one of the arguments to the stored proc call?

For some reason, the following message causes 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 file is a compilation failure:

Msg 156, Level 15, State 1, Line 5 Incorrect syntax next to the keyword 'CONVERT'.

Changing it to the following problem fixes:

 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; 
+4
source share
1 answer

Stored procedure parameters cannot contain expressions; they must be constant values ​​or @ variables. In your example, CONVERT() is an expression and therefore not allowed.

The same is true for default parameter values.

+4
source

Source: https://habr.com/ru/post/1382537/


All Articles