将 TSQL 查询转换为 Access

发布于 2024-11-15 08:29:58 字数 976 浏览 2 评论 0原文

我想将此查询隐藏到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

榕城若虚 2024-11-22 08:29:58

在将 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

生活了然无味 2024-11-22 08:29:58

我立即发现了一些“问题”:

  1. Access SQL 不支持CASE。由于您的两个 CASE 语句都是双值的,因此请使用 Iif(,,)
  2. Access 对于在括号中设置多个连接非常挑剔。 “从最后到第一个”工作,捕获一组括号中的最后一个连接(两个表名称 - 在本例中您的子选择是其中一个 - 和 ON 字段之间的连接( s)),然后是另一个右括号,它在前一个连接的表名之前打开,&c。直到除了第一个表名(和第一个 JOIN)之外的所有内容都用括号括起来。 (不过,不要被愚弄——这实际上并没有强制执行评估顺序)。
  3. 我认为 Access 需要 LEFT JOIN 而不是 LEFT OUTER JOIN,但这可能并不重要。
  4. Access 可能不支持“强制使用 Unicode”N'string' 运算符。我从未使用过它,但实际上不会发誓它是错误的(在上下文中)。
  5. Access 更喜欢使用双引号来分隔字符串,而不是单引号。不过,它通常接受单引号。

这可能无法解决您的问题,但可能会让您朝着正确的方向前进。

A few "problems" I'm seeing right off the bat:

  1. Access SQL doesn't support CASE. Since both your CASE statements are two-valued, use Iif(<condition>, <true_part>, <false_part>).
  2. Access is very picky about having multiple joins set off in parentheses. Work "last to first", catching the last join in a set of parens (both table names--in this case your sub-select is one of them--the join between and the 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 first JOIN) enclosed in parens. (Don't be fooled though--this does not actually enforce an order of evaluation).
  3. I think Access wants LEFT JOIN rather than LEFT OUTER JOIN, but this might not matter.
  4. Access may not support the "force to Unicode" N'string' operator. I've never used it, but won't actually swear that it's wrong (in context).
  5. Access prefers double quotes to set off strings, rather than single. It usually accepts single quotes, though.

This may not solve your problem, but it may get you headed in the right direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文