SQL新手,請接受我的道歉。查詢的創建,當病例情況中斷需要協助修復
If HBL_CLNT_CAT._HS_EB_CODE1 = 'BF' then value = TBM_BILLGRP._HS_EB_DET1
If HBL_CLNT_CAT._HS_EB_CODE2 = 'BF' then value = TBM_BILLGRP._HS_EB_DET2
的_HS_EB_DET#
但是超過100個字符添加一個「*」。
在協助下開發了一個查詢,但是它破壞了條件規則,因爲'then語句/操作會失敗,因爲它比條件語句(select _hs_eb_code1 from hbl_cat where hs_eb_code = '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
向hbl_cat添加UNIQUE約束沒有意義嗎?那麼插入重複項時將失敗,而不是在選擇重複項時。 – VladV