Solved

if else

Posted on 2006-11-23
2
901 Views
Last Modified: 2008-01-09
hi there
as
T1.HLOC = IF T2.HLOC  IS MISSING THEN '.' ELSE T2.HLOC   dont work in db2
whts the other way around
thanks
bobby
SELECT  
 T1.HLOC  ,
 T2.HLOC
FROM
   (STG_PURCHDE1_WR T1  LEFT OUTER JOIN V_RRR_PURCHDE2_WR T2
       ON
  T1.HCOMP  = T2.HCOMP
 AND T1.HDIV  = T2.HDIV
AND T1.DPORD#  = T2.DPORD#
AND T1.DLINE#  = T2.DLINE#
AND T1.HLOC = IF T2.HLOC  IS MISSING THEN '.' ELSE T2.HLOC  )
0
Comment
Question by:bobby2929
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 18006773
hi
what you need is the case expression  :
 T1.HLOC = IF T2.HLOC  IS MISSING THEN '.' ELSE T2.HLOC

will be

T1.HLOC = CASE WHEN T2.HLOC IS NULL THEN '.'
                         WHEN SOME-OTHER-CONDITION THEN SOME-OTHER-VALUE
                          ELSE T2.HLOC END

you have to write the END in order to close the case clause

momi
0
 
LVL 7

Accepted Solution

by:
sachinwadhwa earned 50 total points
ID: 18007368
or use COALESCE function

T1.HLOC = COALESCE(T2.HLOC , '.')

COALESCE(T2.HLOC , '.') will return T2.HLOC,  if T2.HLOC is not null otherwise '.'

more help here:

http://publib.boulder.ibm.com/infocenter/db2luw/v8//topic/com.ibm.db2.udb.doc/admin/r0000780.htm
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question