Using select to determine a stored procedure parameter

Viewed 39

I am calling a stored procedure where I'm trying to cast a number into a datetime (as I'm grabbing it from excel so it converts dates to numbers:

exec UpdateInvoices @InvoiceDate = select cast(cast(42109 as datetime) as date)

This doesn't work, I get incorrect syntax near Select.

What's the correct way of doing this?

2 Answers

You need to set your parameter first.

DECLARE @DateParam date 

SELECT  @DateParam = cast(cast(42109 as datetime) as date)
EXEC UpdateInvoices @InvoiceDate = @DateParam

Just lose the select:

exec UpdateInvoices @InvoiceDate = cast(cast(42109 as datetime) as date)
Related