Just algorithm!

Sql - Command สำหรับ Select แบบ Join String

ไปอ่านเจอมาจาก ที่นี่ ครับ
คือว่า Oracle จะมี Command wm_concat ไว้สำหรับ Join string
แต่ Sql ดันไม่มีคำสั่งนี้ ซะนี่

วิธีแก้ไขคือใช้คำสั่ง FOR XML ครับ
สมมติว่า ต้องการ join Col1 จากตาราง Table1 ด้วย comma
เขียนอย่างนี้ครับ

SELECT
    (SELECT Col1 + ', '
     FROM Table1
     FOR xml path('')) AS csv




 

Create Date : 28 พฤษภาคม 2553    
Last Update : 10 พฤศจิกายน 2557 21:03:14 น.
Counter : 542 Pageviews.  

1  2  

chaowman
Location :
กรุงเทพฯ Thailand

[Profile ทั้งหมด]

ฝากข้อความหลังไมค์
Rss Feed
Smember
ผู้ติดตามบล็อก : 8 คน [?]





New Comments
Group Blog
 
All Blogs
 
Friends' blogs
[Add chaowman's blog to your web]
Links
 

 Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved.