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

Dynamic Order By clouse 1

Status
Not open for further replies.

vpekulas

Programmer
Jan 8, 2002
154
CA
I have the following SP, how can I pass in the field name
that the recordset should be sorted by ? I want @FieldName
to be the field name ......

CREATE PROCEDURE sp_Index
@FieldName varchar(50)
AS
SELECT ID, fldS, fldEnable, fldMulti, fldSHOWRES, fldEDATE, fldACTIVE
FROM poll_tbl_poll
ORDER BY @FieldName ASC
Go


"Taxes are the fees we pay for civilized society"
 
Code:
CREATE PROCEDURE sp_Index
   @FieldName varchar(50)
AS
exec('SELECT ID, fldS, fldEnable, fldMulti, fldSHOWRES, fldEDATE, fldACTIVE
   FROM poll_tbl_poll
   ORDER BY ' + @FieldName )
Go
 
Thanks swampBoogie, that did it.
BTW why did u use the exec command. Wouldn't it work with out it as well ?

"Taxes are the fees we pay for civilized society"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top