我正在尝试创建一个sql语句,其中我希望根据条件显示列。我尝试了以下方法:
IF (T0."Confirmed" = "Y")
BEGIN
SELECT T0."DocNum",T1."VisOrder", T1."Quantity", T1."Price", T0."CardCode", T0."CardName", T1."OpenCreQty", T0."CreateDate", T0."Printed", T0."Confirmed", T0."U_ACM_O_ETD", T2."DocDate", T0."U_ACM_O_LOS"
FROM OPOR T0 INNER JOIN POR1 T1 ON T0."DocEntry" = T1."DocEntry", OWTQ T2
END
ELSE
BEGIN
SELECT T0."DocNum",T1."VisOrder", T1."Quantity", T1."Price", T0."CardCode", T0."CardName", T1."OpenCreQty", T0."CreateDate", T0."Printed", T0."Confirmed", T0."U_ACM_O_ETD", T2."DocDate", T0."U_ACM_O_LOS"
FROM OPOR T0 INNER JOIN POR1 T1 ON T0."DocEntry" = T1."DocEntry", OWTQ T2
END
但是当我尝试运行它时,它告诉我if语句附近有一个不正确的语法。
[sap ag][libodbchdb dll][hdbodbc]语法错误或访问冲突;257 sql语法错误:“if”附近语法不正确:第1行第1列(ecm2)(位置1)
更新:
我更新了密码
select
case
when T2."Confirmed" = 'Y' then
(SELECT T0."DocNum", T0."CardCode", T0."CardName", T0."NumAtCard",
T1."DocDate", T1."ReqDate", T0."U_ACM_ORDERINFO", T2."DocNum",
T2."CardCode", T2."CardName", T2."U_ACM_CONTAINERLOAD",
T2."U_ACM_O_ETD", T2."U_ACM_A_ETD", T2."Confirmed"
FROM ORDR T0 , OPRQ T1, OPOR T2)
when T2."Confirmed" = 'N' then
(SELECT T0."DocNum", T0."CardCode", T0."CardName", T0."NumAtCard",
T1."DocDate", T1."ReqDate", T0."U_ACM_ORDERINFO", T2."DocNum",
T2."CardCode", T2."CardName", T2."U_ACM_CONTAINERLOAD",
T2."U_ACM_O_ETD", T2."Confirmed"
FROM ORDR T0 , OPRQ T1, OPOR T2)
end
更新的错误
[sap ag][libodbchdb dll][hdbodbc]语法错误或访问冲突;257 sql语法错误:第8行第1列“”(ecm2)(位置693)
希望你们能指出我做错了什么。
暂无答案!
目前还没有任何答案,快来回答吧!