Convert to a stored procedure call?

I have the following SQL fragment that does not work:

declare @id INT; 
set @id=0; 
exec insert_mail @id OUTPUT, 'ZLgeOZlqRGC6l57TyD/xYQ==', 4928, '2010\01\14\14\03131_2.eml', 'Suz, Katie and Kourtney' Housewarming Party', CONVERT(DATETIME, '2015-01-18 14:03:13', 120); 
select @id;

and changing it thus captures this:

declare @id INT; 
set @id=0; 
declare @p_valid_until datetime;
set @p_valid_until=CONVERT(DATETIME, '2015-01-18  14:03:13', 120)
exec insert_mail @id OUTPUT, 'ZLgeOZlqRGC6l57TyD/xYQ==', 4928, '2010\01\14\14\03131_2.eml', 'Suz,  Katie and Kourtney' Housewarming Party', @p_valid_until; 
select @id;

Can anyone explain?

Cheers, Ian

+3
source share
3 answers

In the first case, you call the CONVERT function in a run command that is not allowed. You cannot call functions when passing arguments

EXECUTE insert_mail ... CONVERT(DATETIME, '2015-01-18 14:03:13', 120)

I see no reason to use the convert function. Just enter the date without conversion.

-2
source

You cannot call functions when passing arguments. These parameter values ​​are expected to be constant or parameters.

+8
source

.. , ...

+1

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


All Articles