要把图2显示成图1的方法:要用到stuff函数,并且图1显示的时间有所截断。
图2sql,只是很普通的sql
select * from Access_Statistics where SFZH=‘152923199608242120‘ and CONVERT(varchar(100), SKSJ, 112)=‘20161015‘ order by SKSJ
图1sql,用了stuff拼接
select dz.XM as 姓名,dz.JSZH as 卡号,[刷卡时间]=stuff((select ‘,‘+substring(CONVERT(varchar(100), SKSJ, 8),0,6) from Access_Statistics where SFZH=mj.SFZH and CONVERT(varchar(100),SKSJ, 112)=‘20161015‘ and SFZH=‘152923199608242120‘ order by SKSJ for xml path(‘‘) ), 1, 1, ‘‘) from Access_Statistics mj inner join Readers dz on dz.SFZH = mj.SFZH inner join XX04 bj on dz.BJBH=bj.BJBH where CONVERT(varchar(100), mj.SKSJ, 112)=‘20161015‘ and mj.SFZH=‘152923199608242120‘ group by mj.SFZH,dz.XM,dz.JSZH
时间: 2024-11-06 23:07:37