?
Solved

how to write if then else in select

Posted on 2005-05-12
3
Medium Priority
?
3,184 Views
Last Modified: 2008-01-09
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
Comment
Question by:bobby2929
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
BigSchmuh earned 375 total points
ID: 13994141
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
 

Author Comment

by:bobby2929
ID: 13995025
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
 
LVL 18

Expert Comment

by:BigSchmuh
ID: 13995414
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

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

850 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