sql server - Define a table type parameter -


i try create table type parameter called "listofname", , set parameter of such type in procedure. error incurred:

must declare scalar variable "@table_name_list"

but declare

 create type listofname table (table_name nvarchar(50) );   create procedure sptest      @table_name_list    listofname   readonly       select * dbo.table_size_daily         table_name in (@table_name_list)   go 

if add statement before definition chunk,

 declare @table_name_list  listofname; 

the error was:

the variable name '@table_name_list' has been declared. variable names must unique within query batch or stored procedure.

how can fix it? lot

i can see there misconception on table type is. though there 1 column in table type, can't treat single-column argument.

consider table type parameter other table irrespective of number of columns have.

in order fix issue, prefer where condition change below:

where table_name in (select table_name @table_name_list)  

however, recommend read few tutorials on table type before proceed implementation. ex: this table valued parameters article on msdn gives clear insight it.


Comments