當出現多筆重複的資料列,但是只有最後幾個欄位不一樣,並且希望將資料變成同一列就好,資料結構 長的像圖一一樣的方式,這時候 如何利用sql的方式去合併資料 並且將資料漂亮的呈列出來

  

 

透過SQL 的寫法 將希望組合的欄位 組合在一起 寫法
將資料用A跟/A串聯起來之後,在用,分隔符號去取代A跟/A
replace(replace(xmlagg(xmlelement(A,trim(code))),'',''),'',',') 完整的寫法 select name, replace(replace(xmlagg(xmlelement(A,trim(code))),'',''),'',',') as code,meno from AAA group by name,meno
執行之後的資料就

 

變成這樣子的資料之後 要如何在轉變成網頁上欄位呈現的資料 如下圖

 

先把表格畫好 表頭也先註解好,之後就將資料作比對
if Instr(adors("code"),"A001")> 0 then response.write "ˇ" else response.write " " end if
這樣子就可以畫出漂亮的資料來了

arrow
arrow
    全站熱搜

    Pescados 發表在 痞客邦 留言(1) 人氣()