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

时间:2019-03-01 09:59:54

标签: 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

3 个答案:

答案 0 :(得分:2)

要发表您的评论

  

不是用逗号声明多个变量的方法吗?

好吧,是的,可以使用逗号来声明多个 local 变量和 cursors ,但 变量-docs明确地说:

  

Response.Cookies.Clear(); FormsAuthentication.SignOut(); Session.Abandon();

     

是一个占位符,指示可以指定多个变量   和分配的值。声明变量时,   变量必须是n中声明的唯一变量   声明。

答案 1 :(得分:1)

#btnMoveMe {
  background-color: blue;
  color: white;
  right: 30px;
  top: 12px;
  position: absolute;
}
.k-dialog-titlebar {
  position: relative;
}

答案 2 :(得分:1)

如下更改

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