数据库
首页 > 数据库> > sql 拼接字符串单条拆分多条

sql 拼接字符串单条拆分多条

作者:互联网

   SELECT   *
   FROM     ( SELECT    A.WS_ID ,
                        B.NEXT_OPERATOR
              FROM      ( SELECT    WS_ID ,
                                    [NEXT_OPERATOR] = CONVERT(XML, '<root><v>'
                                    + REPLACE([NEXT_OPERATOR], ',', '</v><v>')
                                    + '</v></root>')
                          FROM      WS_INST_STEP MYSTEP
                          WHERE     MYSTEP.NEXT_OPERATOR IS NOT NULL
                          GROUP BY  MYSTEP.WS_ID ,
                                    MYSTEP.NEXT_OPERATOR
                        ) A
                        OUTER APPLY ( SELECT    NEXT_OPERATOR = N.v.value('.',
                                                              'varchar(100)')
                                      FROM      A.[NEXT_OPERATOR].nodes('/root/v') N ( v )
                                    ) B
            ) TT
   WHERE    TT.NEXT_OPERATOR IN ( 870, 47, 51, 37, 60, 48, 46, 866, 54, 62, 63,
                                  30, 56, 36, 867, 28, 58, 31, 43, 45, 32, 42,
                                  65, 1892, 64, 40, 55, 34, 50, 53, 29, 57, 59,
                                  44, 795, 41, 52, 35, 33, 869, 868, 1891, 38,
                                  39, 49, 61 )

拼接字符串单条拆分多条

标签:MYSTEP,NEXT,拼接,WS,sql,OPERATOR,单条,ID,SELECT
来源: https://www.cnblogs.com/myloveblogs/p/11320752.html