2011-09-22 80 views
1

不熟悉SQL並且正在開發查詢過程中,使用ETL過程的複製部分。Select Case查詢不起作用

賬單code1 = bf,然後設置爲債務代碼1.如果結算字段(債務代碼)超過100個字符,則添加'*'作爲前綴。

但是查詢會下降,因爲計費代碼1 = bf將單個結果集返回到返回大型結果集的債務代碼1。

select 
    case when len(format) > 100 then left(format, 100) + '*' 
    else format end as format 
from (select case when exists (select _hs_eb_code1 from hbl_cat where hs_eb_code = 'bf) 
        then tbm_bllgrp._hs_eb_det1 end) as format 
from tbm_bllgrp 

想法歡迎。

+0

哪些DBMS您使用這個給你一些想法? –

+1

爲什麼你不能在子查詢中使用'WHERE'子句? – JNK

+0

SQL服務器會考慮使用where子句。 – Nobody

回答

0
select 
case when len(format) > 100 then left(format, 100) + '*' 
else format end as format 
from tbm_bllgrp b 
    inner join hbl_cat hc on hc._hs_eb_code1 = b._hs_eb_det1 

這只是一個猜測,因爲我沒有你的exactl模式和預期產出,但我希望