1

我想在 Pervasive 中使用 case 语句,因为它也缺乏对 Coalesce 的支持。但似乎 Pervasive 8 也缺乏对 Case 语句的支持。

所以我想检查我的问题是否有替代解决方案。

SELECT top 100 
STOCKTR.PHEADPR,
'' as tom
,case Pheadpr.BLNO when <> '' then Pheadpr.BLNO else STOCKTR.PHEADPR end as BLNO
,Pheadpr.custno
,Pheadpr.cust_name
,Pheadpr.company_name
,Pheadpr.company_city
,Pheadpr.invno
,Pheadpr.curr_code
,STOCKTR.RECID
,STOCKTR.ARTNO
,STOCKTR.DATE
,STOCKTR.QTY_PCS
,STOCKTR.PRICE_SEK_PCS
,STOCKTR.ULAND  
FROM STOCKTR INNER JOIN PHEADPR
ON PHEADPR.NO = STOCKTR.PHEADPR
WHERE STOCKTR.TRCODE='02' AND STOCKTR.PHEADPR <> '0'
order by STOCKTR.DATE desc

所以我的问题集中在我的选择语句中的第四行,上面写着

case Pheadpr.BLNO when <> '' then Pheadpr.BLNO else STOCKTR.PHEADPR end as BLNO

我希望这会产生 1 列输出。在普遍的 8 中有没有办法解决这个问题,以便我可以从我的查询中获得类似案例的行为?

作为旁注,我正在使用 JDBC 驱动程序并从 Java 程序中进行查询。

4

1 回答 1

1

您可以使用 IF 语句。语法是:

IF ( 搜索条件 , 表达式 , 表达式 )

因此,在您的情况下,您可能需要以下内容:

IF ( Pheadpr.BLNO <> '' , Pheadpr.BLNO, STOCKTR.PHEADPR) 作为 BLNO

如果可能的话,您应该考虑升级到 PSQL V11 的当前版本,同时支持 CASE 和 COALESCE 语句,并且成为受支持的 PSQL 版本。

于 2012-03-15T13:11:56.410 回答