[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

Stored procedures - passing table as param

How do i write a SP to pass a tablename as param into a STORED procedure (SP)

i.e i wanna do

SELECT COUNT(*) FROM @TABLE
0
jedistar
Asked:
jedistar
1 Solution
 
bwdowhanCommented:
Hi jedistar,

You will need to use dynamic sql:


create proc getall @v_tablename varchar(20)
  as
BEGIN

DECLARE @SQL VARCHAR(100)
SET @SQL = 'SELECT * FROM ' + @v_tablename

EXEC (@SQL)

END

0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now