Write the sql to a variable first i.e. SELECT @mydynamicsql = 'SELECT * FROM mytable ORDER BY '+@orderbyvalue
EXECUTE (@mydynamicsql) > -----Original Message----- > From: Brian Ferrigno [mailto:[EMAIL PROTECTED]] > Sent: 15 October 2001 22:11 > To: SQL > Subject: RE: Stored Procedure help > > > Thanks Eric, > > I had tried removing the quotes but received an error I did. > > The error I got was: > "Error 1008: The SELECT item identified by the ORDER BY > number 1 contains a > variable as part of the expression identifying a column > position. Variables > are only allowed when ordering by an expression referencing a > column name" > > Apparently SQL Server stored procedures don't like using > variables in the > ORDER BY clause. > > Have you ever run across this error? Any other suggestions > for this problem? > > > > Brian > > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > Sent: Monday, October 15, 2001 4:14 PM > To: SQL > Subject: Re: Stored Procedure help > > > Don't enclose the variable @OrderBy in quotes. Because it > was defined as > type varchar, the db already knows it's a string. > |------------------------+------------------------------------ > ------------| > |Eric A. Laney |You will be where you most desire > to be in a | > |Systems Engineer |short while. > | > |LAN Optimization Team | > | > |Verizon Data Services | > | > |Voice: 813.978.4404 | > Today's Fortune| > |Pager: 888.985.8519 | > | > |------------------------+------------------------------------ > ------------| > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get the mailserver that powers this list at http://www.coolfusion.com Archives: http://www.mail-archive.com/[email protected]/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
