1. 程式人生 > >insert函式小記與stuff函式對比

insert函式小記與stuff函式對比

    
-- insert函式
SELECT
    id,
    ( INSERT ( ( SELECT group_concat( realname ) FROM staff_tbl WHERE psn = 'c0c2c19c-9bb4-11e8-9d65-000c2964' ), 3, 2, 'zz' ) ) AS myIdea 
FROM
    staff_tbl a 
GROUP BY
    id
結果如下:將boss改成bozz
1    bozz,趙潛,孫黎
2    bozz,趙潛,孫黎
57    bozz,趙潛,孫黎
 

-- stuff函式
stuff (( SELECT ',' + realname FROM staff_tbl WHERE psn = 'c0c2c19c-9bb4-11e8-9d65-000c2964' FOR XML path ( '' ) ),1,1,'')