0

I have this code:

declare @countTable int;  
set @countTable = 1;

create table #TempDadosExport 
(
     defprodutoid int, 
     nome varchar(250), 
     Categoria varchar(250),
     tipoorigem varchar(250),
     Campanha varchar(250), 
     PopUpId int
);

insert into #TempDadosExport(defprodutoid, nome, Categoria, tipoorigem, Campanha, @countTable)

But when I try to use @countTable to insert, I get this error:

Incorrect syntax near '@countTable'.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

You can't specify a column name as a variable in an insert statement unless you use dynamic SQL.

Your insert is specifying a list of columns to insert into, but no values.

I suspect what you mean to write is

insert into #TempDadosExport(defprodutoid, nome, Categoria,tipoorigem,Campanha,popupid) select defprodutoid, nome, Categoria,tipoorigem,Campanha, @countTable from OTHERTABLE
alroc
  • 27,574
  • 6
  • 51
  • 97