select convert(nvarchar(25),in_gentime, 107) AS LogInDate,
convert(nvarchar(25),in_gentime, 108) as LogInTime,
convert(nvarchar(25),out_gentime, 107) AS LogOutDate,
convert(nvarchar(25),out_gentime, 108) as LogOutTime
from in_time_temp i, out_time_temp o where in_gentime between '10/01/2011 00:01' and '11/18/2011 23:59'
and i.cardnumber = 'MCL1570' and out_gentime between '10/01/2011 00:01' and '11/18/2011 23:59' and o.cardnumber = 'MCL1570'
and month(in_gentime) = month(out_gentime) and day(in_gentime) = day(out_gentime)
and year(in_gentime) = year(out_gentime) order by year(in_gentime), year(out_gentime),
month(in_gentime), month(out_gentime), day(in_gentime), day(out_gentime)
輸出這個查詢將返回這樣的:修改查詢以獲得這樣
Login Date LoginTime Logout date logouttime
Oct 11, 2011 08:06:00 Oct 11, 2011 22:02:00
Oct 12, 2011 08:35:00 Oct 12, 2011 21:14:00
Oct 14, 2011 08:21:00 Oct 14, 2011 21:59:00
Oct 15, 2011 08:21:00 Oct 15, 2011 21:59:00
假設如果該記錄是有in_time_temp和記錄是不是有out_time_temp表意味着它應該表現出像輸出在這個時間的情況下登錄這個....
是有二零一一年十月十三日在此in_time_temp但登錄退房時間尚未在此out_time_temp
如何修改脫身像這樣:
Login Date LoginTime Logout date logouttime
Oct 11, 2011 08:06:00 Oct 11, 2011 22:02:00
Oct 12, 2011 08:35:00 Oct 12, 2011 21:14:00
Oct 13, 2011 08:21:00
Oct 14, 2011 08:21:00 Oct 14, 2011 21:59:00
Oct 15, 2011 08:21:00 Oct 15, 2011 21:59:00
如何修改我的查詢?
SQL服務器真的不打算做很多格式化 - 你應該在前端(應用程序,報告工具等)做到這一點 –
如何在前端做我不做記錄或插入或不是 – Nathan
報告工具像SQL Server Reporting Services或Crystal Reports通常具有特定的選項來抑制*重複值... –