我正在使用SQL SERVER 2008 R2。我想要獲取多個值,並在同一行中逐行顯示它,如果值存在,則顯示一些值,並且可能是單列上的'12值'的可能性。如何在SQL SERVER 2008 R2中逐行顯示多個值?
對於實施例,下面的屏幕截圖,它示出了用於除了註釋相同的數據記錄。我想顯示爲單個記錄,但意見應顯示兩個值是ASN及時性,準確性ASN,問題報告。這三個值使用相同的船廠「0096a」逐行顯示。
我的示例查詢,
SELECT
D30.SPGD30_SHIP_SITE_C AS SHIPSITE,
D30.SPGD30_RATING_MONTH_Y AS RATINGMONTH,
D30.SPGD30_PRIOR_SCORE_R AS PRIOR,
D30.SPGD30_REVISED_SCORE_R AS REVISED,
CASE WHEN (CHARINDEX('-',D30.SPGD30_TRACKED_ADJUSTMENT_X) > 0) THEN CONVERT(VARCHAR(8), CAST(D30.SPGD30_TRACKED_ADJUSTMENT_X AS DATETIME) , 1) ELSE D30.SPGD30_TRACKED_ADJUSTMENT_X END ADJUSTMENTS,
J02.SPGJ02_MSG_CODE_X AS COMMENTS,
D30.SPGD30_LAST_TOUCH_Y AS LASTUPDATED,
D30.SPGD30_LAST_TOUCH_C AS LASTUPDATEDCDSID
FROM
CSPGD30_TRACKING D30,
CSPGD31_TRACKING_RATING_ELEMNT D31,
CSPGA04_RATING_ELEMENT_MSTR A04 ,
CSPGJ02_MSG_OBJ J02
WHERE
D30.SPGA02_BUSINESS_TYPE_C = D31.SPGA02_BUSINESS_TYPE_C
AND
D30.SPGA03_REGION_C = D31.SPGA03_REGION_C
AND
D30.SPGD30_SHIP_SITE_C = D31.SPGD30_SHIP_SITE_C
AND
D30.SPGD30_RATING_MONTH_Y = D31.SPGD30_RATING_MONTH_Y
AND
D30.SPGD30_TRACKED_ADJUSTMENT_X = D31.SPGD30_TRACKED_ADJUSTMENT_X
AND
D30.SPGD30_LAST_TOUCH_Y = D31.SPGD30_LAST_TOUCH_Y
AND
D31.SPGA04_RATING_ELEMENT_D = A04.SPGA04_RATING_ELEMENT_D
AND
A04.SPGJ02_MSG_K = J02.SPGJ02_MSG_K
AND
D30.SPGA02_BUSINESS_TYPE_C = 'serv'
AND
D30.SPGA03_REGION_C = 'ap'
AND
D30.SPGD30_SHIP_SITE_C = '0134a'
ORDER BY
D30.SPGD30_SHIP_SITE_C ASC ,
D30.SPGD30_RATING_MONTH_Y DESC ,
D30.SPGD30_LAST_TOUCH_Y DESC
你想要的結果是什麼?有很多列,你想展示哪些列? – 2013-02-18 09:39:23
我想在單個列中顯示多個值(12個評分元素)。例如,如果存在8個評級要素,我們在單個列中只顯示8個評級要素。 – 2013-02-18 09:42:36
你應該看看這個:[http://stackoverflow.com/questions/1574407/how-to-concatenate-n-columns-into-one](http://stackoverflow.com/questions/1574407/how-to -concatenate-n-columns-into-one) – Dalex 2013-02-18 15:45:15