Link to home
Start Free TrialLog in
Avatar of bobby2929
bobby2929

asked on

how to write if then else in select

hi there,
col 1   AA BB CC DD (Table 1)

         Col2     BB CC DD EE (Table 2)
       
        Col 3     Bell , CAMBRIDGE   (Table 2)


       Col4
  If data in col1(BB) = data in col(BB) THEN WRITE  BELL   else null

How can write sql plz advice    
thanks
Bobby
ASKER CERTIFIED SOLUTION
Avatar of BigSchmuh
BigSchmuh
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bobby2929
bobby2929

ASKER

while i am runnuing this query i am not getting everything i mean data is there but it dont match with everything, so i try trim
i thing db2 doesnt recoginze trim plz advice whts bext approach
SELECT
CASE WHEN stg_cust5.TERRITORY_CODE = STG_arrg.Rest_of_the_key  THEN STG_ARRG.CUST_TERRITORY_ENGLISH  ELSE Null END
FROM STG_CUST5, STG_ARRG
fetch first 50 rows only


so i try
SELECT
CASE WHEN trim(stg_cust5.TERRITORY_CODE) = trim(STG_arrg.Rest_of_the_key ) THEN STG_ARRG.CUST_TERRITORY_ENGLISH  ELSE Null END
FROM STG_CUST5, STG_ARRG
fetch first 50 rows only


You have an LTRIM and a RTRIM functions available in DB2 but I think the problem is not there...

There is no JOIN condition which means every STG_CUST5 is linked to every STG_ARRG thus resulting in more than the 50 first rows having non corresponding territory.
==> Can you explain what you are functionnaly looking for
hth