将 TSQL 查询转换为 Access
我想将此查询隐藏到 Access 2007。 每次我尝试运行它时,都会收到“查询表达式中缺少运算符”的语法错误。
我很感激任何帮助
SELECT
u.UserID,
u.FirstName,
u.LastName,
u.Username,
u.Email,
u.DisplayName,
upd.TypeOfAccess,
upd.kusfCompanyCode FROM dbo.dnn_Users AS u INNER JOIN
dbo.dnn_UserRoles AS ur ON u.UserID = ur.UserID INNER JOIN
dbo.dnn_Roles AS r ON ur.RoleID = r.RoleID AND (r.RoleName = N'KUSF Agent' OR r.RoleName = N'KUSF Company With Agent' OR r.RoleName = N'KUSF Company Without Agent') LEFT OUTER JOIN
(SELECT
up.UserID,
MAX(CASE WHEN ppd.PropertyName = 'TypeOfAccess' THEN up.PropertyValue ELSE '' END) AS TypeOfAccess,
MAX(CASE WHEN ppd.PropertyName = 'kusf CompanyCode' THEN up.PropertyValue ELSE '' END) AS kusfCompanyCode
FROM
dbo.dnn_UserProfile AS up INNER JOIN
dbo.dnn_ProfilePropertyDefinition AS ppd ON
up.PropertyDefinitionID = ppd.PropertyDefinitionID AND ppd.PortalID = 0
GROUP BY up.UserID) as upd on u.UserID = upd.UserID
I like to covert this query to Access 2007.
Every time I try to run it, I get a Syntax Error Missing operator in query Expression.
I appreciate any help
SELECT
u.UserID,
u.FirstName,
u.LastName,
u.Username,
u.Email,
u.DisplayName,
upd.TypeOfAccess,
upd.kusfCompanyCode FROM dbo.dnn_Users AS u INNER JOIN
dbo.dnn_UserRoles AS ur ON u.UserID = ur.UserID INNER JOIN
dbo.dnn_Roles AS r ON ur.RoleID = r.RoleID AND (r.RoleName = N'KUSF Agent' OR r.RoleName = N'KUSF Company With Agent' OR r.RoleName = N'KUSF Company Without Agent') LEFT OUTER JOIN
(SELECT
up.UserID,
MAX(CASE WHEN ppd.PropertyName = 'TypeOfAccess' THEN up.PropertyValue ELSE '' END) AS TypeOfAccess,
MAX(CASE WHEN ppd.PropertyName = 'kusf CompanyCode' THEN up.PropertyValue ELSE '' END) AS kusfCompanyCode
FROM
dbo.dnn_UserProfile AS up INNER JOIN
dbo.dnn_ProfilePropertyDefinition AS ppd ON
up.PropertyDefinitionID = ppd.PropertyDefinitionID AND ppd.PortalID = 0
GROUP BY up.UserID) as upd on u.UserID = upd.UserID
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在将 TSQL 查询转换为 Access 2007 查询时查看这组规则,如帖子中所述。也许它将有助于解决您的问题。
转换Microsoft Access (JET SQL) 到 SQL Server (T-SQL) 备忘单
Check out this set of rules while converting TSQL query to Access 2007 query as outlined in the post. Probably it will help to solve your issue.
Convert Microsoft Access (JET SQL) to SQL Server (T-SQL) Cheatsheet
我立即发现了一些“问题”:
CASE
。由于您的两个CASE
语句都是双值的,因此请使用Iif(,,)
。ON
字段之间的连接( s)),然后是另一个右括号,它在前一个连接的表名之前打开,&c。直到除了第一个表名(和第一个JOIN
)之外的所有内容都用括号括起来。 (不过,不要被愚弄——这实际上并没有强制执行评估顺序)。LEFT JOIN
而不是LEFT OUTER JOIN
,但这可能并不重要。N'string'
运算符。我从未使用过它,但实际上不会发誓它是错误的(在上下文中)。这可能无法解决您的问题,但可能会让您朝着正确的方向前进。
A few "problems" I'm seeing right off the bat:
CASE
. Since both yourCASE
statements are two-valued, useIif(<condition>, <true_part>, <false_part>)
.ON
field(s)), then another closing paren after that, which opens just before the table name of the preceding join, &c. until you have all but the first table name (and firstJOIN
) enclosed in parens. (Don't be fooled though--this does not actually enforce an order of evaluation).LEFT JOIN
rather thanLEFT OUTER JOIN
, but this might not matter.N'string'
operator. I've never used it, but won't actually swear that it's wrong (in context).This may not solve your problem, but it may get you headed in the right direction.