sql行列转换的问题
watch_date dangwei zhihui jiguan xingzhen
------------------------------------------------------------
2009-2-3 张朝娜 叶长勇 关炜 万慧阳 李中明 余茂菲 李金键 王照华 陈开义 志勇
有值班表一张 csinfo_watch,其中放有各个部门每天值班的情况
现在需要把这些记录都转换成一列的形式来呈现
watch_date|watch
-----------------------
2009-2-3 张朝娜
2009-2-3 叶长勇
2009-2-3 关炜
2009-2-3 万慧阳
2009-2-3 李中明
2009-2-3 余茂菲
2009-2-3 李金键
2009-2-3 王照华
2009-2-3 陈开义
2009-2-3 志勇
-----------------------
大家帮忙想想办法啊
------最佳解决方案--------------------SELECT watch_date,dangwei FROM csinfo_watch
UNION ALL
SELECT watch_date,zhihui FROM csinfo_watch
UNION ALL
SELECT
watch_date,
SUBSTRING(A.jiguan,B.number,CHARINDEX(' ',A.jiguan+' ',B.number)-B.number) AS watch
FROM csinfo_watch AS A
JOIN master.dbo.spt_values AS B
ON B.type='p' AND B.number BETWEEN 1 AND LEN(A.jiguan)
AND SUBSTRING(' '+A.jiguan,B.number,1)=' '
UNION ALL
SELECT
watch_date,
SUBSTRING(A.xingzhen,B.number,CHARINDEX(' ',A.xingzhen+' ',B.number)-B.number) AS watch
FROM csinfo_watch AS A
JOIN master.dbo.spt_values AS B
ON B.type='p' AND B.number BETWEEN 1 AND LEN(A.xingzhen)
AND SUBSTRING(' '+A.xingzhen,B.number,1)=' '
ORDER BY watch_date
------其他解决方案--------------------watch_date dangwei zhihui jiguan xingzhen
-------------------------------------------------------
2009-2-3 张朝娜 叶长勇 关炜 万慧阳 李中明 余茂菲 李金键 王照华 陈开义 志勇
------其他解决方案--------------------watch_date dangwei zhihui jiguan xingzhen
-------------------------------------------------------
2009-2-3 张朝娜 叶长勇 关炜 万慧阳 李中明 余茂菲 李金键