Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error declaring multiple table variables in SQL

Tags:

sql

sql-server

I have problem declaring multible table variables in Microsoft SQL Server. Trying to separate the tables with comma but seems to give me some syntax errors.

Code looks like this. Show both code as sample and as a picture in order for you to see the error marks:

DECLARE
@StructuredProducts TABLE(
    StructuredProductId INT
    ,ArrangerIdv2 INT
    ,ISIN VARCHAR(50)
    ,InstrumentId INT
    ,Caption VARCHAR(100)
    ,DbRegDate DATE
    ,EndDate DATE
),
@PriceDataOld TABLE(
    StructuredProductId INT
    ,FinalDate DATE
    ,FinalPriceDate DATE
    ,FinalPrice DECIMAL(9,3)
    ,FinalPriceSek DECIMAL(9,3)
),
@PriceDataEarlyExercise TABLE(
    StructuredProductId INT
    ,EEDate DATE
    ,EEPriceDate DATE
    ,EEPrice DECIMAL(9,3)
    ,EEPriceSek DECIMAL(9,3)
),
@PriceDataActive TABLE(
    StructuredProductId INT
    ,ActiveDate DATE
    ,ActivePriceDate DATE
    ,ActivePrice DECIMAL(9,3)
    ,ActivePriceSek DECIMAL(9,3)
)

enter image description here

like image 304
David Avatar asked Mar 04 '23 10:03

David


1 Answers

To address your comment

Isn't comma the way to declare multiple variables?

well, yes a comma can be used to declare multiple local variables and cursors, but not table variables - the docs explicitly say this:

n

Is a placeholder indicating that multiple variables can be specified and assigned values. When declaring table variables, the table variable must be the only variable being declared in the DECLARE statement.

like image 168
AakashM Avatar answered Mar 13 '23 02:03

AakashM