Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table Name as a variable 1

Status
Not open for further replies.

Avacha

Technical User
Apr 1, 2002
69
US
I need to create Stored Procedure using Table Name
and Field Name as variables
If same one knows, please, help me with syntax.
I would greatly appreciate your help.
 
Here's a sample procedure with Table and Field as parameters that executes a query using dynamic SQL:
Code:
CREATE PROC MyProc
  @TableName VARCHAR(20),
  @FieldName VARCHAR(20)
AS

EXEC('SELECT ' + @FieldName+  ' FROM ' + @TableName)
To call it:
Code:
exec MyProc 'TableName', 'FieldName'
-dave
 
Arrrgh... cross post.... thread183-755468.

-dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top