2

我在这个查询上有问题。我怎样才能解决这个问题:

select (select case top 1 STATUS 
       when 'Inprocess' then 'Processing' 
       when 'Inworkbin' then 'Waiting In Draft' 
       end 
    from ICS_EMAIL_CONNECTIONS_TRX A    
    where A.SESSIONID = B.SESSIONID 
    and STATUS <> 'Completed'
    order by A.CREATE_DATE desc) as LAST_STATUS 

我收到此错误:

关键字“top”附近的语法不正确。

有什么建议么?

4

5 回答 5

10

尝试:

select top 1 case STATUS

代替

select case top 1 STATUS 
于 2013-05-02T11:53:19.493 回答
3

您不需要嵌套选择。

select top 1 case STATUS 
             when 'Inprocess' then 'Processing' 
             when 'Inworkbin' then 'Waiting In Draft' 
             end LAST_STATUS
from ICS_EMAIL_CONNECTIONS_TRX A    
where A.SESSIONID = B.SESSIONID 
and STATUS <> 'Completed'
order by A.CREATE_DATE desc;

尽管这可以返回 0 行,而正确编写 TOP 1 的原始表单将始终返回一行,即使值为 NULL。

于 2013-05-02T11:53:22.117 回答
2
select (select top 1 (case STATUS 
   when 'Inprocess' then 'Processing' 
   when 'Inworkbin' then 'Waiting In Draft' 
   end) 
from ICS_EMAIL_CONNECTIONS_TRX A    
where A.SESSIONID = B.SESSIONID 
and STATUS <> 'Completed'
order by A.CREATE_DATE desc) as LAST_STATUS 
于 2013-05-02T11:53:45.403 回答
2

更正大小写和顶级关键字

select (select top 1 case STATUS 
       when 'Inprocess' then 'Processing' 
       when 'Inworkbin' then 'Waiting In Draft' 
       end 
    from ICS_EMAIL_CONNECTIONS_TRX A    
    where A.SESSIONID = B.SESSIONID 
    and STATUS <> 'Completed'
    order by A.CREATE_DATE desc) as LAST_STATUS 
于 2013-05-02T11:54:15.467 回答
1
select top 1 * from (select case STATUS 
       when 'Inprocess' then 'Processing' 
       when 'Inworkbin' then 'Waiting In Draft' 
       end 
    from ICS_EMAIL_CONNECTIONS_TRX A    
    where A.SESSIONID = B.SESSIONID 
    and STATUS <> 'Completed'
    order by A.CREATE_DATE desc) as LAST_STATUS 
于 2013-05-02T12:18:46.613 回答