• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3189
  • Last Modified:

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
0
bobby2929
Asked:
bobby2929
  • 2
1 Solution
 
BigSchmuhCommented:
Use the CASE syntax like the below example

SELECT CASE WHEN Table1.Col1 = Table2.Col2 THEN CHR(7) ELSE Null END
FROM Table1, Table2
...

hth
0
 
bobby2929Author Commented:
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


0
 
BigSchmuhCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now