Passing a variable to a stored procedure | Community
Skip to main content
Level 2
February 26, 2025
Solved

Passing a variable to a stored procedure

  • February 26, 2025
  • 1 reply
  • 369 views

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]

Best answer by ccg1706

Hi @kristenco4,

 

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

 

 

 

 

1 reply

ccg1706
Community Advisor
ccg1706Community AdvisorAccepted solution
Community Advisor
February 27, 2025

Hi @kristenco4,

 

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