I'd like to conditionally control the host variable into which the data from an SQL select statement is retrieved. This is for flexibility, so that I can use the same code in my program more than once.
Here is a code sample:
C/EXEC SQL
C+ If :ResultName = 'AgtMaster'
C+ Then
C+ Fetch Next From MainCursor Into :AgtMasterResults
C+ ElseIf :ResultName = 'TranHistory'
C+ Then
C+ Fetch Next From MainCursor Into :TranHistoryResults
C+ End If
C/END-EXEC
I'm getting an SQL precompiler error though:
SQL0199 Position 10 Keyword IF not expected. Valid tokens: DECLARE
This is referring to the first statement. I don't understand if this is because I'm missing something, or if it's because conditions can't be used in an embedded SQL block.
Has anyone done something similar?
ASKED:
Dec 4 2008 6:25 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _