Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SELECT WITH ISNULL

Former Member
0 Likes
1,535

SELECT ISNULL(tabA-Col1, tab-Col2) AS Col

FROM tabA INNER JOIN tabB

ON .....

If Col1 from table tabA is null, then I need to get Col2 from table tabB.

How can I make this query work ?

6 REPLIES 6
Read only

Former Member
0 Likes
975

HI,

Try this

Select a~Col1 b~col2
    from dbtab1 as a
    inner join dbtab2 as b 
     ON a~<field> = b~<field> 
          .......
      INto table itab
     Where a~col1 Eq space.

Read only

matteo_montalto
Contributor
0 Likes
975

Did you try...

SELECT tabB-Col2

FROM tabA INNER JOIN tabB

ON .....

WHERE tabA-Col1 EQ SPACE.

?

Hope it helps.

Read only

0 Likes
975

Col1 may or may not be Null. Only if Col1 is null, get Col2. Both the above query will not work.

Read only

0 Likes
975

Try left outer join :

SELECT TAB1~col1
              TAB2~col1
              from TAB1 LEFT OUTER JOIN TAB2
              INTO <TABLE>
              WHERE TAB1 = ' '.

Hope this resolves your issue.

Regards,

Gurpreet

Read only

christine_evans
Active Contributor
0 Likes
975

>

> SELECT ISNULL(tabA-Col1, tab-Col2) AS Col

> FROM tabA INNER JOIN tabB

> ON .....

>

> If Col1 from table tabA is null, then I need to get Col2 from table tabB.

>

> How can I make this query work ?

If want you want to do is replace the tablea field with the tableb field if the tablea field is null, this is something you could probably do quite easily in real SQL (Oracle) using NVL.

SELECT NVL(a.field,b.field)
FROM tab1 a, tab2 b
WHERE ....(put the join here - I don't know what your join would be).

.....though thinking again perhaps not because you don't get proper null fields in SAP; blank fields contain white spaces rather than nulls. In which case you could use a decode instead.

In SAP's open SQL I don't think I would even bother trying to do anything clever, because it is not possible. It's easy enough to select both fields into an internal table and use ABAP to decide which one you want.

Read only

0 Likes
975

Coming from a SQL Server background, I thought this could be done without using Open SQL. Guess, I will have to do the check in ABAP code. Thanks for your input.