|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Databases > DB2 Development > Help needed for Dynamically changing sort by field and order by clause, in procedure |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|