Quantcast
Channel: SCN : Unanswered Discussions - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 4343

Usage of Control statement to dynamically manage Query iteration

$
0
0

Hi,

 

I have a scenario wherein the Query iteration needs to be controlled dynamically based on Input Parameter. I feel this scenario can be managed only byCursor but I am not sure about the usage of Control Statement within cursor to manage SQL iteration dynamically. Please suggest options other than Cursor in case you disagree.

 

Given scenario will provide you more clarity on my question.

 

Scenario:

 

In the given scenario Start Date/End Date will be provided by the Input Parameter. Consider Start Date/End Date is '20150105'/'20150315', then for each Month i.e Jan2015, Feb2015 and Mar2015 I need to get the ID numbers greater than the Maximum ID number from last month.

i.e. ID numbers for 20150101-20150131 should be greater than Maximum ID number from Dec2014, ID's of Feb2015 should be greater than Jan2015 and of Mar2015 should be greater than Feb2015. Also if same ID exist in multiple months then consider the ID only once when it appeared for the first month.

I can get Maximum ID number for Dec2014, Jan2015 and Feb2015 using Group By. Based on the Maximum ID and Input Months, I can get ID's greater than these prior months Max ID's for given date range.

 

Question:

 

How can I use Control Statement/Loop within the cursor that can dynamically control the SQL execution based on Input Parameter(
Number of months in given Date Range).

So if the Input Parameters is 20150105-20150315 then based on number of months, the Select Query should be executed 3 times to get ID's for each month greater than prior month Maximum ID's.

 

Finally how can I combine output of this 3 month in a single variable.

 

 

Any response will be much appreciated.

 

 

 

 

Regards

Randhir Jha


Viewing all articles
Browse latest Browse all 4343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>