sql - 在 SQL 中声明多个表变量时出错

标签 sql sql-server

我在 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)
)

enter image description here

最佳答案

解决您的评论

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/

相关文章:

java - 雪花无法显示/解释 unicode '\u0089'

mysql - 如何将一个简单的数组作为列数据?

sql - 取消分组效果?

mysql - 从 MS SQL 中的值更新 MySQL 数据库

sql - 如果存在还是存在?

sql - 如何返回存在空值的表中的列名?

sql - oracle中的区间函数

SQL - 将表传递给 Select 中的 UDF

sql-server - 为选择中的每一行重新分配变量的令人惊讶的行为

sql-server - SSDT 无法从 SQL Server Service Broker 找到存储过程