DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 4th, 2007, 11:00 PM
itsforbiju itsforbiju is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 2 itsforbiju User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 52 sec
Reputation Power: 0
Question Help needed for Dynamically changing sort by field and order by clause, in procedure

Hello,

i have requirement where i have to do order by on the field that i give as input to the store procedure.Also i have to change the sorting direction, ASC or DESC

folowing is the stored proc i tried.Although its error free and getting deployed .the result returned on execution is,not sorted as per the input i gave.

CREATE PROCEDURE SP_TESTPAGE (
IN current_sort_field VARCHAR(64),
IN current_sort_order VARCHAR(64),
IN sso_id VARCHAR(64)
)
DYNAMIC RESULT SETS 1
P1: BEGIN

-- Declare cursors
DECLARE cursor CURSOR WITH RETURN FOR
SELECT SESSION_ID, FROM_DATE, DESCRIPTION FROM TACTP00.PAGINATION
ORDER BY current_sort_field ;


OPEN cursor;
--END CASE;
END P1

The another aproach i tried was to put seperate select query with order by on each cloumn with a declared cursor with it.And open only one cursor based on the check whether current_sort_field(input to stored proc) is column1 or column2.This works fine, but this will bring up lots of if conditons in the stored proc as the number of columns in the table increases. It would be great if i can make the first approach work.

Can any body help

Regards

Biju

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > Help needed for Dynamically changing sort by field and order by clause, in procedure


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 2 hosted by Hostway