[英]Converting Oracle SQL to TSQL
I have the following Oracle SQL:我有以下 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:这是我尝试将其转换为 microsoft sql server 的 TSQL:
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
消息 4145,级别 15,状态 1,第 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消息 156,级别 15,状态 1,第 34 行
Incorrect syntax near the keyword 'OR'.关键字“OR”附近的语法不正确。
Msg 102, Level 15, State 1, Line 34消息 102,级别 15,状态 1,第 34 行
Incorrect syntax near ')'.')' 附近的语法不正确。
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.