2013-08-16 30 views
0

我有两列名为PNO和RNO都是VARCHAR其中有一个订单号,现在我的要求是我使用一个case语句提取两列,并选择他们到一个单个列

如果RNO是不是空它应该打印实际生成,如果它不是它的预测生成

如果pno不为空那么它应该打印和解否则产生的预测

我的查询是:

select 
     case 
     when (pno!=null) then 'Reconciled' 
     when (pno=null) then 'Forecast1 Generated' 
     when (rno=null) then 'Forecast Generated' 
     when (rno!=null) then 'Actual Generated' 
     end as Status 
from tablexyz 

,当我执行它我只得到无论是PNO或RNO case语句导致set.my有望走出放应返回所有的case语句。我无法使用和在case case condition中,因为我需要所有的记录。 我在Dbvisualizer上运行这个。

在此先感谢。

回答

0

您应该使用pno is not null代替pno!=null在SQL.SQL使用三个值逻辑,并pno!=null是未知的,这是不正确的也不假,但事实并非如此,这种情况是不取。

所以你的语句应该看起来像

select 
     case 
     when (pno is not null) then 'Reconciled' 
     when (pno is null) then 'Forecast1 Generated' 
     when (rno is null) then 'Forecast Generated' 
     when (rno is not null) then 'Actual Generated' 
     end as Status 
from tablexyz 
+0

对不起提这晚我DBVisualizer工具使用 –

相关问题