Hi i need to write a query on the following requirement.

SELECT COMM_TEXT
INTO :WS_MIKM_COMM_TEXT
FROM MPIPROD.MIKMV01
WHERE ACCOUNT_NO = :WFD_ACCOUNT_NO
AND (SUBSTR(COMM_TEXT,1,39) = :WS_COMMENT_TEXT
AND SUBSTR(COMM_TEXT,47,14) = :WS_DENY_DESC)
OR (SUBSTR(COMM_TEXT,1,39) = :WS_COMMENT_TEXT)

The above query is to be modified. The requirement is if
both the fields are equal then that has to be given
priority. In the above query if it satisfies any one it
comes out without checking if both being equal is possible.

Answer Posted / satish

SELECT COMM_TEXT
INTO :WS_MIKM_COMM_TEXT
FROM MPIPROD.MIKMV01
WHERE (CASE WHEN (SUBSTR(COMM_TEXT,1,39 = :WS_COMMENT_TEXT)
AND SUBSTR(COMM_TEXT,47,14) = :WS_DENY_DESC)) THEN 1
ELSE
(SUBSTR(COMM_TEXT,1,39) = :WS_COMMENT_TEXT) THEN 2
END) IN (1,2)
AND ACCOUNT_NO = :WFD_ACCOUNT_NO


Tell me if i am wrong??


ACCOUNT_NO = :WFD_ACCOUNT_NO
AND CASE
OR (SUBSTR(COMM_TEXT,1,39) = :WS_COMMENT_TEXT)

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you simulate the explain of an embedded sql statement in spufi/qmf?

634


Define declaration generator (dclgen).

667


How is the value function used?

602


While unloading huge amount of data from table. Suddenly job failed some error. Imagine 1M data unloading, In that 90% data unloaded only 10% left, So if want to unload the rest 10% what needs to be done? Whether do i need to start from top or anything ?

1818


What is difference between isnull and coalesce?

620






Which are the db2 tools to protect integrity of the database?

690


If the cursor is kept open followed the issuing of commit, what is the procedure to leave the cursor that way?

704


What is phantom read in db2?

636


What is rebind in db2?

576


What are the bind parameters ibm db2?

624


what is utility for parm lib

1876


Is db2 a database?

574


DB2 can implement a join in three ways using a merge join, a nested join or a hybrid join. Explain the differences?

2277


How many databases can be created inside an instance in db2 ?

599


How do you concatenate the firstname and lastname from emp table to give a complete name?

603