views:

37

answers:

3

Hi all,

I have the following piece of SQL 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''s Housewarming Party', CONVERT(DATETIME, '2015-01-18 14:03:13', 120); 
select @id;

and changing it this way fixes it:

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''s Housewarming Party', @p_valid_until; 
select @id;

Anybody can explain?

Cheers, Jan

+2  A: 

You can't call functions in the passing of arguments. These parameter values are expected to be constants or parameters.

Aaron Bertrand
+1  A: 

You can't pass functions, etc. to stored procedures, only variables or constant values...

Sparky
A: 

In the first case you are calling the CONVERT function in an execute command which is not allowed. You can't call functions in the passing of arguments

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

I don't see the point of using the convert function. Just type date in without convert.

Yada