Expand my Community achievements bar.

SOLVED

Passing a variable to a stored procedure

Avatar

Level 1

Is it possible to pass a variable to a stored procedure?  I am pulling the deliveryid and setting it as a variable but when I execute the stored procedure, I am getting an error:

 

ODB-240000 ODBC error: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Error converting data type nvarchar to bigint. SQLState: 37000

 

DeliveryId data type is an integer but I am not sure if the SQL is taking the variable literally.

 

Here is my logic:

EXEC [CDL].[dbo].[test] @deliveryid = [vars.deliveryId]

1 Accepted Solution

Avatar

Correct answer by
Level 8

Hi @kl28morr,

 

The above error is showing you that deliveryid is being treated as a nvarchar instead of an integer (bigint).

 

You will need to try to convert the variable befor passing it to a stored procedure. I would be somehitng like this:

EXEC [CDL].[dbo].[test] @deliveryid = CONVERT(BIGINT, [vars.deliveryId])

Alternatively, if it this does not work you can try CAST function.

 

Finally, I leave you with useful documentation:

CAST AND CONVERT (TRANSACT -Sql) 

Create a stored procedure 

 

Hope it helps, if you need more guidance please let me know.

 

Regards,

Celia

 

 

 

 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 8

Hi @kl28morr,

 

The above error is showing you that deliveryid is being treated as a nvarchar instead of an integer (bigint).

 

You will need to try to convert the variable befor passing it to a stored procedure. I would be somehitng like this:

EXEC [CDL].[dbo].[test] @deliveryid = CONVERT(BIGINT, [vars.deliveryId])

Alternatively, if it this does not work you can try CAST function.

 

Finally, I leave you with useful documentation:

CAST AND CONVERT (TRANSACT -Sql) 

Create a stored procedure 

 

Hope it helps, if you need more guidance please let me know.

 

Regards,

Celia