If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Using Host Variable to Compare with Literal

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-25-08, 09:16
mrhrbacek mrhrbacek is offline
Registered User
 
Join Date: Oct 2007
Posts: 6
Using Host Variable to Compare with Literal

We ran across SQL that compared a host-variable against a literal value in a Where clause in a COBOL program (part of cursor declaration). It came in the form of the following:

ColumnA = :ws-host-var1 and
ColumnB = :ws-host-var2 and
ColumnC = :ws-host-var3 or :ws-host-var3 = ' '

My question is how this will evaluate (particularly for ColumnC)? I can find no examples of this kind of predicate, and one article that says any comparison of a host variable to a literal is a Stage 2 predicate.

What are the rules of comparing host variables to a literal in a where clause?
Reply With Quote
  #2 (permalink)  
Old 11-25-08, 12:46
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
It would be a stage 2 predicate and ColumnC would not be elligible for matching index access. You'll run into those types of SQL from time to time. In fact, I just ran into one last month, that I asked the developer to move into cobol prior to executing the SQL, so that we could get index access.
(CASE :WS-HV1
WHEN 'xxx' THEN '06'
WHEN 'yyy' THEN '06'
ELSE :WS-HV2 END) = A.column1
They could very easily determine if they want to use the value 06 prior to executing the query and move 06 to their host variable, WS-HV2. They would use an IF/ELSE then the SQL would look like:
:WS-HV2 END = A.column1

I could swear there used to be something in the application programming and SQL guide, though I can't find it at present. Its not even mentioned in Table 88. (Predicate types and processing). I'm sure that several of the leading writers have written about it at some point or another.

Dave Nance
Reply With Quote
  #3 (permalink)  
Old 11-25-08, 14:43
mrhrbacek mrhrbacek is offline
Registered User
 
Join Date: Oct 2007
Posts: 6
The one thing I found was a reference to a comparison between host variable and literal as being Stage 2 in an article by Bonnie Baker.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On