日期:2014-05-18 浏览次数:20411 次
use Tempdb go --> --> if not object_id(N'Tempdb..#T') is null drop table #T Go Create table #T([num] int,[d] int,[t] int,[start] Datetime,[end] Datetime) Insert #T select 2,4,33,'08:46:33','08:48:45' union all select 8,2,30,'08:57:18','08:58:19' union all select 11,5,27,'09:01:00','09:03:17' union all select 12,2,35,'09:04:08','09:05:18' union all select 13,5,27,'09:05:30','09:07:49' Go Select a.[num],[d]-b.number AS d,a.[t],CONVERT(VARCHAR(8),DATEADD(s,33,[start]),8) AS [start],CONVERT(VARCHAR(8),DATEADD(s,33,[end]),8) AS [end] from #T AS a,master.dbo.spt_values AS b WHERE a.d>b.number AND b.type='P' /* num d t start end 2 4 33 08:47:06 08:49:18 2 3 33 08:47:06 08:49:18 2 2 33 08:47:06 08:49:18 2 1 33 08:47:06 08:49:18 8 2 30 08:57:51 08:58:52 8 1 30 08:57:51 08:58:52 11 5 27 09:01:33 09:03:50 11 4 27 09:01:33 09:03:50 11 3 27 09:01:33 09:03:50 11 2 27 09:01:33 09:03:50 11 1 27 09:01:33 09:03:50 12 2 35 09:04:41 09:05:51 12 1 35 09:04:41 09:05:51 13 5 27 09:06:03 09:08:22 13 4 27 09:06:03 09:08:22 13 3 27 09:06:03 09:08:22 13 2 27 09:06:03 09:08:22 13 1 27 09:06:03 09:08:22 */