Showing posts with label table in store procedure. Show all posts
Showing posts with label table in store procedure. Show all posts

Sunday, 27 September 2015

HOW TO PASS TABLE NAME IN SQL

Find the procedure to pass table as parameter and execute in sql.


declare @tblnm nvarchar(max)             --- declare parameter for select query
declare @tab nvarchar(max)                   -- pass table name
declare @para1 nvarchar(max)              -- pass parameter for where condition.


set @tblnm='select * from ' +@tab    + ' where col_1 ' + @para1    ----- set the query in parameter

exec sp_executesql @tblnm                    ----execute sql within store procedure.