Wednesday, May 29, 2013

How to pass table name as parameter to the Stored procedure in SQL server

If we pass table name as parameter to the stored procedure , we can use single stored procedure for different  tables  which contains same column names and data types. For this follow the stored procedure below

create procedure Test(@table_name varchar(max))
as
declare @va  varchar(max)
begin
set @va = 'select * from ' + @table_name
EXEC(@va)
RETURN
end 

No comments:

Post a Comment