sql - Table variable in a stored procedure -


i create simple stored procedure take parameter existing tables.

i thought procedure should work:

@userid int, @tablename varchar(255) begin     if(@userid not null)     begin        update t        set t.productid = 100        dbo.[@tablename] t      end 

when execute stored procedure table name, query completed errors:

invalid object name 'dbo.@tablename'.

any advice?

you'd have following:

declare @sql nvarchar(100) set @sql = 'update ' + @tablename + ' set t.productid = 100 ' exec sp_executesql @sql 

note: have no where clause items in @tablename updated.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -