Hi All,
I've written a stored proc that accepts an argument. When I reference the argument in the WHERE section it works. Now, I've tried to write another proc that accepts the name of the table to query, but it does not want to work. How can I pass a string variable to a stored proc and use the argument in the FROM clause. Here is my procedure:
CREATE PROCEDURE sp_GetVolumesPerAccount (@TableName as char(20))
AS
SELECT * from @TableName
The error I get is "Incorrect Syntax near '@TableName'"
Any help will be appreciated. Thanks a lot.
I've written a stored proc that accepts an argument. When I reference the argument in the WHERE section it works. Now, I've tried to write another proc that accepts the name of the table to query, but it does not want to work. How can I pass a string variable to a stored proc and use the argument in the FROM clause. Here is my procedure:
CREATE PROCEDURE sp_GetVolumesPerAccount (@TableName as char(20))
AS
SELECT * from @TableName
The error I get is "Incorrect Syntax near '@TableName'"
Any help will be appreciated. Thanks a lot.