我在 Microsoft SQL Server 中声明多表变量时遇到问题。试图用逗号分隔表格,但似乎给了我一些语法错误。
代码看起来像这样。将代码显示为示例和图片,以便您查看错误标记:
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)
)
最佳答案
解决您的评论
Isn't comma the way to declare multiple variables?
好吧,是的,逗号可用于声明多个局部变量和游标,但是 不是 表变量 - docs明确地说:
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.
关于sql - 在 SQL 中声明多个表变量时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54942176/