拆分字符串为单条记录

2010-04-18_201757

原来的数据如上图上图,需要得到的结果如下图

2010-04-18_202054

sql语句如下:

   1: SELECT  vo.name_id ,
   2:           COMNAME = SUBSTRING(vo.COMNAME, number,
   3:                               CHARINDEX(',', vo.COMNAME + ',', number)
   4:                               - b.number)
   5:   FROM    dbo.verna_org AS vo
   6:           JOIN master..spt_values b ON b.type = 'p'
   7:                                        AND CHARINDEX(',', ',' + vo.COMNAME,
   8:                                                      number) = number

你可能感兴趣的:(字符串)