Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rsegecin
Yak Posting Veteran
82 Posts |
Posted - 2007-03-21 : 13:53:40
|
| I knew in SQL server and now I'm using SQl Server 2005. Does somebody knows what is wrong with that procedure?create procedure teste@PageOrder varchar(10),@PageWay bitAsBeginif (@PageWay = 1) begin Select * order by @PageOrder asc from friends endelse begin Select * order by @PageOrder desc from friends endEndGo |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-03-21 : 13:59:43
|
| Select * order by @PageOrder asc from friendss.bSelect * from friends order by xxxxx asccan't use a variable in the order by clauseSelect * from friends order by case when @PageOrder = 'mycol' then mycol end asc, case when @PageOrder = 'mycol2' then mycol2 end asc, case when @PageOrder = 'mycol3' then mycol3 end ascor maybeexec ('Select * from friends order by ' + @PageOrder + ' asc')but the use will need permission on the table.And someone will tell you to watch out for injection.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|