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通常具有特定的选项来抑制*重复值... –