如果那么在SQL中声明OpenEdge

时间:2013-01-15 11:45:11

标签: sql if-statement openedge

我正在通过ODBC向一个OpenEdge数据库发出if语句。我的查询工作就像一个魅力,但Progress希望我定义if语句不同,我不知道。是否有人可以为我定义正确的查询?

    IF            
    {Crediteur code|type=string} = 'HOEFASTE'
 BEGIN       
    (SELECT
        inok."vest-kd-arvo"+RTRIM('-') + RIGHT(CAST((inok."inok-nr" + 1000000) AS varchar(7)),6) AS inokvalue
        ,RTRIM("leso-kd")+RTRIM('-')+inok."vest-kd-arvo"+RTRIM('-')+CAST("inok-nr"AS varchar(6)) AS inokdisplay
        ,RIGHT(CAST((inok."inok-nr") AS varchar(7)),6) + '-' + inok."vest-kd-arvo" + '-' + RTRIM("leso-kd") AS inoknr
        ,RTRIM("leso-kd") AS soortfact
    FROM
        PUB.inok
    WHERE
        inok."vcdc-nr" = {Administratie|type=int32}
        AND inok."inss-kd" NOT IN ('H','G')
    )
ELSE        
    (SELECT   
        inok."vest-kd-arvo"+RTRIM('-') + RIGHT(CAST((inok."inok-nr" + 1000000) AS varchar(7)),6) AS inokvalue
        ,RTRIM("leso-kd")+RTRIM('-')+inok."vest-kd-arvo"+RTRIM('-')+CAST("inok-nr"AS varchar(6)) AS inokdisplay
        ,RIGHT(CAST((inok."inok-nr") AS varchar(7)),6) + '-' + inok."vest-kd-arvo" + '-' + RTRIM("leso-kd") AS inoknr
        ,RTRIM("leso-kd") AS soortfact
    FROM
        PUB.inok
    WHERE
        inok."rela-kd-kre" = {Crediteur code|type=string}
        AND inok."vcdc-nr" = {Administratie|type=int32}
        AND inok."inss-kd" NOT IN ('H','G')
     )
END

1 个答案:

答案 0 :(得分:1)

如果我理解正确,只有WHERE - 条款不同,基于“Crediteur代码”。

您可以在WHERE - 子句中移动IF。这将为您留下一个SELECT语句。这个替代方案对你有用吗?

SELECT   
    inok."vest-kd-arvo"+RTRIM('-') + RIGHT(CAST((inok."inok-nr" + 1000000) AS varchar(7)),6) AS inokvalue
    ,RTRIM("leso-kd")+RTRIM('-')+inok."vest-kd-arvo"+RTRIM('-')+CAST("inok-nr"AS varchar(6)) AS inokdisplay
    ,RIGHT(CAST((inok."inok-nr") AS varchar(7)),6) + '-' + inok."vest-kd-arvo" + '-' + RTRIM("leso-kd") AS inoknr
    ,RTRIM("leso-kd") AS soortfact
FROM
    PUB.inok
WHERE
    inok."rela-kd-kre" = (CASE WHEN {Crediteur code|type=string} = 'HOEFASTE' THEN inok."rela-kd-kre" ELSE {Crediteur code|type=string} END)
    AND inok."vcdc-nr" = {Administratie|type=int32}
    AND inok."inss-kd" NOT IN ('H','G')