Wednesday, September 3, 2014

Dynamic SQL in SQR Program

INPUT command prompts the user to enter value and that dynamic value can be used in sql query to fetch user requested data. 

sample SQR code for dynamic sql:

begin-program
 do call_dynamic_sql
end-program

begin-procedure call_dynamic_sql
INPUT $state maxlen=2 type=char 'Enter State Acronym'
let $state=upper($state)
begin-select
name (,1)
state (+1,1)
 position (+1)
from  customers
where state=$state
end-select
end-procedure !call_dynamic_sql

Once you process the above code (INPUT command) will prompt you to enter value





after that the supplied value will be passed to "Where" clause which is supposed to filter data.

where state=$state will be added as dynamically to the query and renders data only for entered value.


No comments:

Post a Comment