位置表:
Locid Locname
--------------
8 Blooimng dale
LocVtypeAssign_tbl:
locid vtid
----------- -----------
8 7
8 8
Transaction_tbl:
transactID Locid vtid dtime Paydate
--------- ----- ---- ----------------------- ----------------------
7497 8 7 2013-06-28 14:39:34.000 2013-06-28 18:28:20.000
7500 8 8 2013-06-28 14:41:57.000 NULL
如果我通过 Locid 8,我如何获得 vtid 7 和 vtid 8 的日期差之和。我正在使用以下公式找到日期差:
sum(DATEDIFF(hour,t.Paydate,t.DelDate))
预期输出:
location datediff of 7 datediff of 8
Blooming Dale 2206:30321:73242 235:3373:56915
有没有办法编写存储过程来获取这个输出?
我试过这样的查询:
SELECT convert(varchar(10),sum(DATEDIFF(hour,t.Paydate,t.DelDate)))+':'
+convert(varchar(10),sum(DATEDIFF(minute,t.Paydate,t.DelDate)% 60)) + ':'
+convert(varchar(10),sum(DATEDIFF(SECOND,t.Paydate,t.DelDate)% 60))
AS ' HH:MM:SS'
FROM Transaction_tbl t
WHERE t.Locid=8 group by vtid
我得到这样的输出:
HH:MM:SS
----------------
2206:30321:73242
235:3373:56915