2017-09-15 76 views
-1

有人能告诉我我的case语句有什么问题吗?带有子查询的SQL Case语句

select 
(case 
     when (select top 1 descr from t1 inner join t2 on t2.id = t1.id where t1.code = '17418')= 'C' Then 'Cancelled'<br/> 
     when (select top 1 descr from t1 inner join t2 on t2.id = t1.id where t1.code = '100020')= 'CL' Then 'Closed'<br/> 
     when (select top 1 descr from t1 inner join t2 on t2.id = t1.id where t1.code = '1105')= 'R' Then 'Reserved'<br/> 
     when (select top 1 descr from t1 inner join t2 on t2.id = t1.id where t1.code = '1106')= 'S' Then 'Scheduled' <br/> 
     else null end) <br/> 
From table 
+1

为什么你觉得有什么错呢? –

+0

这是有效的代码还是伪代码?什么是“从表格”? – Parfait

+0

它只是拉第一个陈述而不是其他 – Jason312

回答

1

我觉得你想要做这样的事情:)

select CASE t1.descr 
    WHEN 'C' THEN 'Cancelled' 
    WHEN 'CL' THEN 'Closed' 
    WHEN 'R' THEN 'Reserved' 
    WHEN 'S' THEN 'Schedule' 
    ELSE 
END as descr_Text 
    from t1 
inner join t2 on t2.id = t1.id 
where t1.code in('17418','100020','1105',....)