Evonet
Evonet

Reputation: 3640

Using select to determine a stored procedure parameter

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?

Upvotes: 2

Views: 47

Answers (2)

Marc Gravell
Marc Gravell

Reputation: 1064204

Just lose the select:

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

Upvotes: 1

AB_87
AB_87

Reputation: 1156

You need to set your parameter first.

DECLARE @DateParam date 

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

Upvotes: 1

Related Questions