我一直在閱讀其他類似的「多記錄到一個」的帖子,但要麼似乎無法得到任何工作,或他們並不真正適用於我想要做的。SQL Server 2008 ssrs多個記錄到一個
這是我的3張桌子。車輛,vehicle_repair評論
vehicle
列:vehicle_name等車輛相關信息,vehicle_make,vehicle_modelvehicle_repair
列:vehicle_name,vehicle_repair_type,vehicle_repair_num,等等等等comments
列:vehicle_name,vehicle_repair_num,comments_detail
程序寫入的方式,如果我寫了多於1行的註釋,它不會連接它們,它會爲每行寫入1個條目,即:
comments
表:
vehicle_name vehicle_rpr_num comments_detail
--------------------------------------------------------------------
150 1 replaced hose
750 1 replaced belt
750 2 replaced fuel and also saw that the
750 2 timing belt needs to be replaced
750 2 as well
我嘗試使用類似:
select
substring((select ' '+comments_detail AS 'data()'
from comments
for xml path('')), 3, 80) as 'comments_detail'
from
comments
我試圖添加一個連接和其他表的子內,但隨後comments_details成爲各頂起,就像它一次結合20條評論而不是1條。
我寧願從頭開始,看看我能否以另一種方式工作。
我試圖鏈接上面的3個表時遇到了我的問題。
我不知道如何把在我從車表需要其他字段,即vehicle_make,vehicle_model
任何想法?我寫我的連接完全錯了嗎?我試圖把它放到一個存儲過程中,這樣一個觀點會更好嗎?
你能告訴你用來拉這個數據的查詢??? –
+1提供示例數據並顯示努力 – Bryan