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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

field name be a variable 1

Status
Not open for further replies.

nnmmss

Programmer
Sep 7, 2004
123
0
0
IR
i have a procedure like this

CREATE PROCEDURE GetFieldPath @FieldName varchar(10), @ReturnField varchar(10) output
AS
Select @ReturnField=@FieldName FROM TblPath


it doesn't work , i want to have field as a variable to pass it different field
which part is wrong?
 
Code:
CREATE PROCEDURE GetFieldPath
 @FieldName varchar(10),
 @ReturnField varchar(10) output
 AS
  DECLARE @lcSQL nvarchar(300)
  SET @lcSQL = 'SELECT @MyReturnField = '+@FieldName+' FROM TblPath'
--- Change the type of parameter to match you needs
 EXEC sp_executesql @lcSQL, N'@MyReturnField varchar(10) OUTPUT', @MyReturnField = @ReturnField OUTPUT
  SELECT @ReturnField

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top