CREATE PROCEDURE dbo.proc_MyStoredProcedure @CompanyName AS SELECT * FROM dbo.[@CompnayName$Item]to return all lines of the item table which belong to the company that I want to specify while calling the stored procedure. To my surprise, SQL created a stored procedure without murmuring . But when I tried to execute the procedure with the following code
EXECUTE dbo.proc_MyStoredProcedure 'My Company Name'it refused to obey me. What can I do?
Comments
Exec ('SELECT * FROM ' + @tableName)
Exec ('SELECT * FROM ' + @MyCompanyName + '$Item')
where @TableName and @MyCompanyName are parameters or variables
I hope it helps.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!