在选择内选择一个案例“扭曲”

时间:2017-08-03 12:32:01

标签: sql sql-server select

SELECT 
        (select CASE 
                WHEN DP_ART_HEAD.KPP_KAT_ART_COD = 'M1' THEN 
                    ROUND(DP_ART_LINES.XONDRIKH - DP_ART_LINES.XONDRIKH * DP_ART_LINES.POSOSTO_EKP_PROT / 100, 2) 
                WHEN DP_ART_HEAD.KPP_KAT_ART_COD = 'M2' THEN 
                    DP_ART_LINES.TIM_MON 
                ELSE 
                    DP_ART_LINES.TIM_MON 
                end AS 'NIKOS' 
        FROM DP_ART_LINES 
        JOIN AP_APO_HEAD ON DP_ART_LINES.EID_CODE = AP_APO_HEAD.EID_CODE 
                        AND DP_ART_LINES.KPP_APO_CODE = AP_APO_HEAD.KPP_APO_CODE 
        JOIN DP_ART_HEAD ON DP_ART_LINES.RN_DP_ART_HEAD = DP_ART_HEAD.RN_DP_ART_HEAD 
        WHERE DP_ART_LINES.EID_CODE = AP_APO_HEAD.EID_CODE
    ), 
    DP_ART_HEAD.KPP_KAT_ART_COD, 
    DP_ART_LINES.EID_CODE AS 'Κωδικός', 
    AP_APO_HEAD.EID_PERIGR AS 'Είδος', 
    DP_ART_LINES.POSOT AS 'Ποσότης', 
    DP_ART_LINES.XONDRIKH AS 'Τιμή Χονδρικής', 
    DP_ART_LINES.POSOSTO_EKP_PROT AS 'Έκπτωση', 
    DP_ART_LINES.FL_DORO AS 'Δώρο' 
FROM DP_ART_LINES 
JOIN AP_APO_HEAD ON DP_ART_LINES.EID_CODE = AP_APO_HEAD.EID_CODE 
                AND DP_ART_LINES.KPP_APO_CODE = AP_APO_HEAD.KPP_APO_CODE 
JOIN DP_ART_HEAD ON DP_ART_LINES.RN_DP_ART_HEAD = DP_ART_HEAD.RN_DP_ART_HEAD

最终结果是

  

Msg 512,Level 16,State 1,Line 1   子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。

显然,我试图在一个单一的价值接受者中从案例陈述中推出一堆价值观。 (当然有)更好的方法吗?

1 个答案:

答案 0 :(得分:0)

子查询可以返回多行。您可以使用前1来阻止这种情况。

此外,我更喜欢在申请中选择外部申请。

尝试以下代码。

.topcenter {

	margin-right: auto;
	margin-left: auto;
	position: relative;
}
.back {
	width: 100%;
	height: auto;
	position: absolute;
	
}
.green {
	background-color: #9AC149;
	}