Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
Posted: Tue May 24, 2016 11:25 am Post subject: Re: SQL vs Cobol loop
vak255 wrote:
I need to check the above query for four conditions.
either or both D7128.ACCT, STOCK can be zeros.
So First passing all the four values WS-MANF, WS-ACCT, WS-STOCK, and WS-PROD.
then passing zeros to STOCK, then for ACCT, then zeros for both
I like to check if this could be done using case\switch in the above SQL itself without checking it outside the query.
Vak255,
Why complicate a simple requirement? If your intention is to get the record when ACCT and STOCK are missing the values then change those two columns to IN and use that in your where clause. something like this
Code:
D7218.ACCT_NUM IN (:WS-zero-acct,:WS-ACCT) AND
D7218.STOCK_NUM In (:Ws-zero-stock,:WS-STOCK) AND
Once you get the results you can pick the record that you want first. You can add an order by to put zero records at the bottom of the result or at top of the result list. _________________ Kolusu
www.linkedin.com/in/kolusu
I was trying to fetch only one record out of the SQL as I need to process this one record further and the priority is it should first check without zeros, if there is a hit then fetch the row and stop,
else try with zeros on STOCK, if no hit,
then try with zeros on ACCT, if no hit
then try with zeros on both.
You are telling that I could fetch the first row by using order by...I got it. thanks.
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
Posted: Tue May 24, 2016 6:08 pm Post subject:
vak255 wrote:
How should I include the NULLs?
ACCT - Numeric
STOCK - AlphaNumeric.
vak255,
If you looked up the syntax for IN predicate or NULL predicate you would have easily figured it out.
Code:
(D7218.ACCT_NUM IN (:WS-zero-acct,:WS-ACCT) OR
D7218.ACCT_NUM IS NULL) AND
(D7218.STOCK_NUM In (:Ws-zero-stock,:WS-STOCK) OR
D7218.STOCK_NUM IS NULL) AND
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum