Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 13th, 2003, 10:51 AM
tolki tolki is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: SC
Posts: 1 tolki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question How do I use a parameter in the order by clause?

Hi all,

I have a few asp pages that execute a stored procedure to get information from a database. The information will include stuff like county and route, etc. I want to be able to click on county and sort by it. how can I do this where when I click on county the stored procedure takes the variable assigned to county and uses it in the order by clause in the stored procedure?

Thanks,
Kim

Reply With Quote
  #2  
Old March 14th, 2003, 03:29 PM
numbernine numbernine is offline
Up To His Eyes In Ads
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Chicago
Posts: 160 numbernine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 25 sec
Reputation Power: 6
Hey Kim,
This article should help you
http://www.sqlteam.com/item.asp?ItemID=2209
(props to Stumpy on this one)

Now, if you figure out how to order one of the columns in descending order, please let me know!

Reply With Quote
  #3  
Old August 8th, 2007, 03:40 AM
freeman2007 freeman2007 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 1 freeman2007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 13 sec
Reputation Power: 0
Quote:
Originally Posted by numbernine
Now, if you figure out how to order one of the columns in descending order, please let me know!


DECLARE @SortOrder tinyint
SET @SortOrder = 2

SELECT CompanyName,
ContactName,
ContactTitle
FROM Customers
ORDER BY CASE WHEN @SortOrder = 1 THEN CompanyName
WHEN @SortOrder = 2 THEN ContactName
ELSE ContactTitle
END DESC

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > How do I use a parameter in the order by clause?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT