SELECT INTO a table variable in T-SQL

前端 未结 8 1882
你的背包
你的背包 2020-11-30 16:55

Got a complex SELECT query, from which I would like to insert all rows into a table variable, but T-SQL doesn\'t allow it.

Along the same lines, you c

8条回答
  •  眼角桃花
    2020-11-30 17:52

    First create a temp table :

    Step 1:

    create table #tblOm_Temp (
    
        Name varchar(100),
        Age Int ,
        RollNumber bigint
    )
    

    **Step 2: ** Insert Some value in Temp table .

    insert into #tblom_temp values('Om Pandey',102,1347)
    

    Step 3: Declare a table Variable to hold temp table data.

    declare   @tblOm_Variable table(
    
        Name Varchar(100),
        Age int,
        RollNumber bigint
    )
    

    Step 4: select value from temp table and insert into table variable.

    insert into @tblOm_Variable select * from #tblom_temp
    

    Finally value is inserted from a temp table to Table variable

    Step 5: Can Check inserted value in table variable.

    select * from @tblOm_Variable
    

提交回复
热议问题