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

Parameter in Order by clause in Cursors

Status
Not open for further replies.

jrdatla

Programmer
Dec 19, 2000
7
US
Can we Use a parameter in the Order by clause of SELECT Statment in the Declarative statment of a Cursor. If so, can you give a small example

Jr. Datla
 
The only way to do this would be to dynamically build a sql string and EXECute it as in:

USE PUBS
GO
DECLARE @mycol sysname,
@sqlstr varchar(1000)
SET @mycol = 'au_lname'
SET @sqlstr = 'SELECT * FROM authors ORDER BY ' + @mycol

EXECUTE (@sqlstr) Tom Davis
tdavis@sark.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top