SQL Server:设置多个值,将它们分配为默认值

时间:2016-05-16 14:44:18

标签: sql sql-server tsql

SET @StartDate = NULL,
    @InitialLoopValue=NULL,
    @FinalLoopValue = NULL, @RootId = NULL, @MakeId = NULL, @CityId = NULL, 
    @CountOfCarsUpdated = NULL, @Url = NULL, @MakeName = NULL, @RootName = NULL, 
    @CityName = NULL, @Content = NULL, @SellInquiryId = NULL, @SellerType = NULL,@imei = NULL;

我有这么多变量,我收到了这个错误。

但是,当我为每个默认分配单独设置SET时,它的工作正常,但这太详细了。

我该如何纠正?

1 个答案:

答案 0 :(得分:7)

您可以使用SELECT一次分配多个变量。

SELECT @StartDate = NULL,
       @InitialLoopValue=NULL,
       @FinalLoopValue = NULL, @RootId = NULL,
       @MakeId = NULL, @CityId = NULL, 
       @CountOfCarsUpdated = NULL, @Url = NULL,
       @MakeName = NULL, @RootName = NULL, 
       @CityName = NULL, @Content = NULL,
       @SellInquiryId = NULL, @SellerType = NULL,@imei = NULL;

注意:未分配变量的默认值为NULL,因此无需= NULL

DECLARE @v INT;
SELECT @v
-- NULL