‎2009 Mar 19 2:44 PM
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 ?
‎2009 Mar 19 2:48 PM
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.
‎2009 Mar 19 2:49 PM
Did you try...
SELECT tabB-Col2
FROM tabA INNER JOIN tabB
ON .....
WHERE tabA-Col1 EQ SPACE.
?
Hope it helps.
‎2009 Mar 19 2:56 PM
Col1 may or may not be Null. Only if Col1 is null, get Col2. Both the above query will not work.
‎2009 Mar 19 4:04 PM
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
‎2009 Mar 19 4:25 PM
>
> 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.
‎2009 Mar 19 5:59 PM
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.