原表结构:
转换后的表结构:
sql:
SELECT TU.Id as UserId,SUBSTRING(TU.WorkingForGroupIds, number ,CHARINDEX(',',TU.WorkingForGroupIds+',',number)-number) as WrokGroupId FROM Team_Users AS TU,master..spt_values s WHERE s.number >=1 AND s.type = 'P' AND SUBSTRING(','+TU.WorkingForGroupIds,s.number,1) = ',' and TU.WorkingForGroupIds<>'' AND TU.WorkingForGroupIds IS NOT NULL