[英]Convert from T-SQL to Access query?
Is there a convenient way to convert this T-SQL query to MS Access? 是否有方便的方法将此T-SQL查询转换为MS Access? The ROUND
and COALESCE
doesn't seem to work in Access. ROUND
和COALESCE
在Access中似乎不起作用。 I'm trying to get the custom AVG
field to run in Access but always gets the syntax error (missing operator) . 我试图让自定义AVG
字段在Access中运行,但始终会收到语法错误(缺少运算符) 。
SELECT TOP 50 [EmployeeID]
,[Last Name]
,[First Name]
,[HrsThisWk]
--AVG HRs
,ROUND(
coalesce((
coalesce([1WksAgo],0) +
coalesce([2WksAgo],0) +
coalesce([3WksAgo],0) +
coalesce([4WksAgo],0) +
coalesce([5WksAgo],0)
)/
nullif(
case when coalesce([1WksAgo],0)=0 then 0 else 1 end +
case when coalesce([2WksAgo],0)=0 then 0 else 1 end +
case when coalesce([3WksAgo],0)=0 then 0 else 1 end +
case when coalesce([4WksAgo],0)=0 then 0 else 1 end +
case when coalesce([5WksAgo],0)=0 then 0 else 1 end,
0),0), 2)
AS '--- AVG HRs ---'
,[1WksAgo]
,[2WksAgo]
,[3WksAgo]
,[4WksAgo]
,[5WksAgo]
FROM [CMHR].[dbo].[tbl52weekHours_20150527]
GROUP BY
[EmployeeID]
,[Last Name]
,[First Name]
,[HrsThisWk]
,[1WksAgo]
,[2WksAgo]
,[3WksAgo]
,[4WksAgo]
,[5WksAgo]
Use NZ
instead of COALESCE
and NULLIF
, and IIF
instead of CASE WHEN
and "..."
instead of [...]
like this: 使用NZ
代替COALESCE
和NULLIF
,并使用IIF
代替CASE WHEN
和"..."
代替[...]
如下所示:
SELECT TOP(50) "EmployeeID"
,"Last Name"
,"First Name"
,"HrsThisWk"
,ROUND(
NZ((
NZ("1WksAgo",0) +
NZ("2WksAgo",0) +
NZ("3WksAgo",0) +
NZ("4WksAgo",0) +
NZ("5WksAgo",0)
)/
NZ(
IIF(NZ("1WksAgo",0)=0, 0, 1) +
IIF(NZ("2WksAgo",0)=0, 0, 1) +
IIF(NZ("3WksAgo",0)=0, 0, 1) +
IIF(NZ("4WksAgo",0)=0, 0, 1) +
IIF(NZ("5WksAgo",0)=0, 0, 1),
0),0), 2)
AS "AVG HRs"
,"1WksAgo"
,"2WksAgo"
,"3WksAgo"
,"4WksAgo"
,"5WksAgo"
FROM "tbl52weekHours_20150527"
GROUP BY
"EmployeeID"
,"Last Name"
,"First Name"
,"HrsThisWk"
,"1WksAgo"
,"2WksAgo"
,"3WksAgo"
,"4WksAgo"
,"5WksAgo"
You can create your query without TOP(50)
and then set the Top Values property to 50
. 您可以创建没有TOP(50)
查询,然后将Top Values属性设置为50
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.