以下是需要转换为MS Access 2003的SQL Server查询:
select distinct u.ssn,u.[name],d.deptname,convert(varchar(12),c.checktime,103)Date,
case when convert(varchar(8),min(checktime),8) between(select convert(varchar(8),checkintime1,8)startin
from schclass_bak where schname like'Morning')and(select convert(varchar(8),checkintime2,8)endin
from schclass_bak where schname like'Morning')
then convert(varchar(8),min(checktime),8) else '0' end MOIN,
isnull(( select max(convert(varchar(8),(checktime),8))
from checkinOut g
where (convert(varchar(8),(checktime),8)) between (select convert(varchar(8),checkouttime1,8)startOut
from schclass_bak where schname like'Morning') and (select convert(varchar(8),checkouttime2,8)endout
from schclass_bak where schname like'Morning') and g.USERID=u.userid and convert(varchar(12),g.checktime,103)=convert(varchar(12),c.checktime,103) ),'12:00')Mout,
case when convert(varchar(8),max(checktime),8) between(select convert(varchar(8),checkintime1,8)startin
from schclass_bak where schname like'Afternoon')and(select convert(varchar(8),checkintime2,8)endin
from schclass_bak where schname like'Afternoon')
then convert(varchar(8),max(checktime),8) else '0' end AIN,
case when convert(varchar(8),max(checktime),8) between(select convert(varchar(8),checkouttime1,8)startOut
from schclass_bak where schname like'Afternoon')and(select convert(varchar(8),checkouttime2,8)endout
from schclass_bak where schname like'Afternoon')
then convert(varchar(8),max(checktime),8) else '17:30' end AOUT
from checkinOut c inner join userinfo u on c.userid=u.userid
inner join departments d on u.defaultdeptid=d.deptid
where cast(convert(varchar(12),c.checktime)as smalldatetime)between '20170401' and '20170425' and u.ssn='50'
group by convert(varchar(12),c.checktime,103) ,u.ssn,u.[name],d.deptname,u.USERID
我感谢任何帮助。感谢
答案 0 :(得分:1)
我稍微改变了你的格式,但大多数情况下,我认为我做对了。
SELECT DISTINCT u.ssn,u.[name],d.deptname,Format(c.checktime,"dd/mm/yyyy") as [Date],
iif( Format(min(checktime),"h:nn:ss") between (select Format(checkintime1,"h:nn:ss") as startin
from schclass_bak where schname like 'Morning')and(select Format(checkintime2,"h:nn:ss") as endin
from schclass_bak where schname like 'Morning')
, Format(min(checktime),"h:nn:ss")
, '0') MOIN,
isnull(( select max(Format(checktime,"h:nn:ss"))
from checkinOut g where (Format(checktime,"h:nn:ss") between (select Format(checkouttime1,"h:nn:ss") as startOut
from schclass_bak where schname like 'Morning') and (select Format(checkouttime2,"h:nn:ss") as endout
from schclass_bak where schname like 'Morning') and g.USERID=u.userid and Format(g.checktime,"dd/mm/yyyy")=Format(c.checktime,"dd/mm/yyyy") ),'12:00')Mout,
iif( Format(max(checktime),"h:nn:ss") between(select Format(checkintime1,"h:nn:ss") as startin
from schclass_bak where schname like 'Afternoon') and (select Format(checkintime2,"h:nn:ss") as endin
from schclass_bak where schname like 'Afternoon')
, Format(max(checktime),"h:nn:ss")
, '0') AIN,
iif( Format(max(checktime),"h:nn:ss") between(select Format(checkouttime1,"h:nn:ss") as startOut
from schclass_bak where schname like 'Afternoon')and(select Format(checkouttime2,"h:nn:ss") as endout
from schclass_bak where schname like 'Afternoon')
, Format(max(checktime),"h:nn:ss")
, '17:30') AOUT
FROM checkinOut c inner join userinfo u on c.userid=u.userid
INNER JOIN departments d on u.defaultdeptid=d.deptid
WHERE Format(c.checktime, "yyyymmdd") between '20170401' and '20170425' and u.ssn='50'
GROUP BY Format(c.checktime,"dd/mm/yyyy"), u.ssn, u.[name], d.deptname, u.USERID
顺便说一下,以下是一些SQL Server到MS Access的转换提示:
答案 1 :(得分:-1)
SELECT DISTINCT u.ssn, u.name, Format(c.checktime,"dd/mm/yyyy") AS [Date], IIf(Format(Min(checktime),"h:nn:ss") Between (select Format(checkintime1,"h:nn:ss") as startin from schclass where schname like 'Morning') And (select Format(checkintime2,"h:nn:ss") as endin from schclass where schname like 'Morning'),Format(Min(checktime),"h:nn:ss"),'0') AS MOIN, IIf((select max(Format(checktime,"h:nn:ss")) from checkinOut g where Format(checktime,"h:nn:ss") between (select Format(checkouttime1,"h:nn:ss") as startOut from schclass where schname like 'Morning') and (select Format(checkouttime2,"h:nn:ss") as endout from schclass where schname like 'Morning') and g.USERID=u.userid and Format(g.checktime,"dd/mm/yyyy")=Format(c.checktime,"dd/mm/yyyy")),(select max(Format(checktime,"h:nn:ss")) from checkinOut g where Format(checktime,"h:nn:ss") between (select Format(checkouttime1,"h:nn:ss") as startOut from schclass where schname like 'Morning') and (select Format(checkouttime2,"h:nn:ss") as endout from schclass where schname like 'Morning') and g.USERID=u.userid and Format(g.checktime,"dd/mm/yyyy")=Format(c.checktime,"dd/mm/yyyy")),'12:00') AS Mout, IIf(Format(Max(checktime),"h:nn:ss") Between (select Format(checkintime1,"h:nn:ss") as startin from schclass where schname like 'Afternoon') And (select Format(checkintime2,"h:nn:ss") as endin from schclass where schname like 'Afternoon'),Format(Max(checktime),"h:nn:ss"),'0') AS AIN, IIf(Format(Max(checktime),"h:nn:ss") Between (select Format(checkouttime1,"h:nn:ss") as startOut from schclass where schname like 'Afternoon') And (select Format(checkouttime2,"h:nn:ss") as endout from schclass where schname like 'Afternoon'),Format(Max(checktime),"h:nn:ss"),'17:30') AS AOUT
FROM checkinOut AS c INNER JOIN userinfo AS u ON c.userid = u.userid
WHERE (((Format([c].[checktime],"yyyymmdd")) Between [dt] And [edate]) AND ((u.ssn) Like [idss]))
GROUP BY u.ssn, u.name, Format(c.checktime,"dd/mm/yyyy"), u.USERID;