本帖最后由 戏子入画丶 于 2016-12-2 14:06 编辑
select A.ChkNo 检验批号,A.ChkItem 检验项目,A.CoSpec 公司规格,A.SupplySpec 供货商规格,B.RelsPort as 卸港码头名称,
(case when (STARTWITH(A.ChkNo, "M") || (STARTWITH(A.ChkNo, "S") && LENGTH(A.ChkNo) = 12))
then A.CoSpec
when (STARTWITH(A.ChkNo, "S") && LENGTH(A.ChkNo) = 10 && !STARTWITH(B.RelsPort, "11075"))
then A.SupplySpec --以S开头
when (STARTWITH(A.ChkNo, "S") && LENGTH(A.ChkNo) = 10 && STARTWITH(B.RelsPort, "11075"))
then A.SupplySpec || A.CoSpec --这里需要输出两个字段
else A.CoSpec end
) as 规格
from DB.TBMRIFCP A LEFT join DB.TBMRSHIPACPT B ON (A.CompId=B.CompId and A.ChkNo =B.ChkNo )