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

SUBQUERY / UNION

Former Member
0 Likes
808

Is there a UNION (ALL) command in OPEN SQL? I'm attempting to join several tables and take the maximum date to be used as output into a text file.

I'm attempting to do something like the following query, but it isn't working:

-


SELECT pernr

MAX(

SELECT begda FROM pa0000 WHERE pernr = wa_pernrs-pernr AND ( begda > c_date AND begda < p_date )

UNION ALL

SELECT begda FROM pa0001 WHERE pernr = wa_pernrs-pernr AND ( begda > c_date AND begda < p_date )

UNION ALL

SELECT begda FROM pa0002 WHERE pernr = wa_pernrs-pernr AND ( begda > c_date AND begda < p_date )

UNION ALL

SELECT begda FROM pa0008 WHERE pernr = wa_pernrs-pernr AND ( begda > c_date AND begda < p_date )

UNION ALL

SELECT begda FROM pa0041 WHERE pernr = wa_pernrs-pernr AND ( begda > c_date AND begda < p_date )

)

INTO TABLE it_dates

FROM pa0000 AS a

INNER JOIN pa0001 AS b ON apernr = bpernr

INNER JOIN pa0002 AS c ON apernr = cpernr

INNER JOIN pa0008 AS d ON apernr = dpernr

INNER JOIN pa0041 AS e ON apernr = epernr

LEFT OUTER JOIN csks AS f ON bkostl = fkostl

" UP TO 1000 ROWS

WHERE ( abegda > c_date AND abegda < p_date ) OR

( bbegda > c_date AND bbegda < p_date ) OR

( cbegda > c_date AND cbegda < p_date ) OR

( dbegda > c_date AND dbegda < p_date ) OR

( ebegda > p_date AND ebegda < p_date ).

Thank you in advance.

3 REPLIES 3
Read only

Former Member
0 Likes
534

Hi Jeff,

There is no such command. You need to built your logic using JOINS and LOOPing around internal tables.

Regards,

Atish

Read only

0 Likes
534

That's kind of what I thought. Just trying to rely on SQL Server experience to limit loops (I have a hard time with that, as cursors (loops) are inherently bad in DB programming)

Thanks

Read only

0 Likes
534

Hi,

a little bit late - I'm almost sure you are allready out of this topic.

I'm in a middle of similar research regarding "union all". Obviously OPEN SQL can't handle UNION additon, but in some cases we may rely on NATIVE SQL, depending on are our statements hardly "OpenSql-ed" or not.

For further similar cases - check the SAP integrated help for a command "EXEC SQL....ENDEXEC". I was curious to find out there is even possibility to create and use stored procedures...

In other words, if you prefer not to rely on open sql sintax (with all its advantages and disadvantages) you may play arround with native sql. I suppose native sql syntax is based on SQL92 standard and all RDBMS specific additions (means Oracle, DB2, MsSql and so on) might not be supported, but never found any topic is that correct or not.

Regards,

Ivaylo Mutafchiev