SQL Server SELECT INTO @variable?

前端 未结 7 1484
走了就别回头了
走了就别回头了 2020-12-02 03:56

I have the following code in one of my Sql (2008) Stored Procs which executes perfectly fine:

    CREATE PROCEDURE [dbo].[Item_AddItem]
        @CustomerId u         


        
7条回答
  •  一生所求
    2020-12-02 04:46

    "SELECT *
      INTO 
        @TempCustomer 
    FROM 
        Customer
    WHERE 
        CustomerId = @CustomerId"
    

    Which means creating a new @tempCustomer tablevariable and inserting data FROM Customer. You had already declared it above so no need of again declaring. Better to go with

    INSERT INTO @tempCustomer SELECT * FROM Customer
    

提交回复
热议问题