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
jedistarAsked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.