0
votes

I have the following Oracle SQL:

    select a.t$orno || '|' || a.t$pono || '|' || a.t$item || '|' || ltrim(rtrim(c.t$dsca)) || '|' || 
a.t$suno || '|' || ltrim(rtrim(b.t$nama)) || '|' || 
a.t$pric || '|' || (a.t$dqua - a.t$iqan) || '|2401|' || a.t$comp || '|' || e.t$cuqp || '|' || e.t$cupp || '|' || (a.t$amnt - a.t$iamt) || '|' || e.t$pacn  || '|' || e.t$dim1  || '|' ||   e.t$dim2                                                             
    || '|' || a.t$reno  || '|' || a.t$srnb
    from baan.ttdpur045310 a, baan.ttccom020310 b, baan.ttiitm001310 c, baan.ttdpur041310 e
    where a.t$srnb > 0
    and   a.t$reno != 0
    and   a.t$dqua !=0
    and   (a.t$dqua - a.t$iqan) != 0
    and   a.t$suno = b.t$suno
    and   ((a.t$suno, a.t$orno, a.t$pono, a.t$srnb) not in (select d.t$suno, d.t$orno, d.t$pono, d.t$srnb from baan.ttdpur046310 d)
    OR ((a.t$suno, a.t$orno, a.t$pono, a.t$srnb) in (select d.t$suno, d.t$orno, d.t$pono, d.t$srnb from baan.ttdpur046310 d WHERE a.t$orno = d.t$orno and a.t$pono = d.t$pono and a.t$srnb = d.t$srnb and a.t$dqua != d.t$qana)))
    and   a.t$item = c.t$item
    and   a.t$orno = e.t$orno
    and   a.t$pono = e.t$pono

Here is my attempt to convert it to TSQL for microsoft sql server:

        select a.t$orno,a.t$pono,a.t$item,ltrim(rtrim(c.t$dsca)),a.t$suno,ltrim(rtrim(b.t$nama)),a.t$pric,(a.t$dqua - a.t$iqan),'2401',a.t$comp,e.t$cuqp,e.t$cupp,(a.t$amnt - a.t$iamt),e.t$pacn,e.t$dim1,e.t$dim2,a.t$reno,a.t$srnb
from    dbo.ttdpur045310 as a,      dbo.ttccom020310 as b, dbo.ttiitm001310 as c, dbo.ttdpur041310 as e
where a.t$srnb > 0
and   a.t$reno != 0
and   a.t$dqua !=0
and   (a.t$dqua - a.t$iqan) != 0
and   a.t$suno = b.t$suno

and   ((a.t$suno, a.t$orno, a.t$pono, a.t$srnb) not exists (select d.t$suno, d.t$orno, d.t$pono, d.t$srnb from dbo.ttdpur046310 as d)
OR ((a.t$suno, a.t$orno, a.t$pono, a.t$srnb) exists (select d.t$suno, d.t$orno, d.t$pono, d.t$srnb from dbo.ttdpur046310 as d WHERE a.t$orno = d.t$orno and a.t$pono = d.t$pono and a.t$srnb = d.t$srnb and a.t$dqua != d.t$qana)))

and   a.t$item = c.t$item
and   a.t$orno = e.t$orno
and   a.t$pono = e.t$pono

I am getting the following error:

Msg 4145, Level 15, State 1, Line 33
An expression of non-boolean type specified in a context where a condition is expected, near ','.
Msg 156, Level 15, State 1, Line 34
Incorrect syntax near the keyword 'OR'.
Msg 102, Level 15, State 1, Line 34
Incorrect syntax near ')'.

1
replace the | with + signsDaniel Marcus
My main issue is with the OR statement in the WHERE clausedog2bert
what is wrong with what u did? what exactly is the error/issue?Daniel Marcus
Change the multi-column in clause into an exists -clause.James Z
Can you please help with the exists clause?dog2bert

1 Answers

0
votes

It would help if you posted any errors you were getting, but I believe this should work:

    SELECT        A.T$ORNO, A.T$PONO, A.T$ITEM, LTRIM(RTRIM(C.T$DSCA)) AS T$DSCA, A.T$SUNO, LTRIM(RTRIM(B.T$NAMA)) AS T$NAMA, A.T$PRIC, A.T$DQUA, A.T$IQAN, A.T$DQUA - A.T$IQAN AS Expr1, '2401' AS Expr2, 
                         A.T$COMP, E.T$CUQP, E.T$CUPP, A.T$AMNT, A.T$IAMT, A.T$AMNT - A.T$IAMT AS Expr3, E.T$PACN, E.T$DIM1, E.T$DIM2, A.T$RENO, A.T$SRNB
 FROM dbo.TTDPUR045310 AS A
INNER JOIN dbo.TTIITM001310 AS C ON A.T$ITEM = C.T$ITEM
INNER JOIN dbo.TTCCOM020310 AS B ON A.T$SUNO = B.T$SUNO
INNER JOIN dbo.TTDPUR041310 AS E ON A.T$ORNO = E.T$ORNO
  AND A.T$PONO = E.T$PONO
 LEFT JOIN dbo.TTDPUR046310 AS d ON A.T$SUNO = d.T$SUNO
  AND A.T$ORNO = d.T$ORNO
  AND A.T$PONO = d.T$PONO
  AND A.T$SRNB = d.T$SRNB
WHERE A.T$SRNB > 0
  AND A.T$RENO <> 0
  AND A.T$DQUA <> 0
  AND (A.T$DQUA - A.T$IQAN) <> 0
  AND d.T$SUNO IS NULL;