Dynamic Table Name in SQL Query
I am working with stored procedures I have to get the table name from an input variable. somehow the stored procedure doesn't seem to be working. The syntax I am using is
CREATE PROCEDURE dbo.SearchDynamicTable
SET NOCOUNT OFF
DECLARE @sqlStatement varchar(300)
SELECT @sqlStatement = "SELECT * FROM " + @v_TableName
SET NOCOUNT ON
but When I call the procedure with input parameter "contact_info" it gives the error that the syntax is wrong near FROMcontact_info. I guess the stored procedure is just concatenating the v_TableName with FROM clause.
Can someone tell me the correct way of writing such stored procedure?