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 ')'.