How to pass table name as stored procedure parameter in SQL Server 2005 (Write stored procedure) ?

 Posted by Bhakti on 11/13/2009 | Category: Sql Server Interview questions | Views: 6399
Answer:

create PROCEDURE Pass_TableName_As_Param --create procedure
@TableName varchar(50) -- Parameter of table name
AS
BEGIN
SET NOCOUNT ON;
SET @TableName= RTRIM(@TableName) --Trim the parameter of table name
DECLARE @cmd AS NVARCHAR(max)
SET @cmd = N'SELECT * -- select query
FROM'+ @table_name
END


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response

More Interview Questions by Bhakti