简体   繁体   English

MS Access SQL 直通查询

[英]MS Access SQL Pass Through Query

I'm trying to rebuild an MS Access (O365 version) Pass through query into an MS SQL query (Server Management Studio version 15.0.18118.0) but i'm getting stuck on one piece of MS Access SQL.我正在尝试重建 MS Access(O365 版本)将查询传递到 MS SQL 查询(Server Management Studio 版本 15.0.18118.0),但我被困在一块 MS Access SQL 上。 It's at the line seen below "A.X_PAGER_CO_ID = P.ROW_ID(+)".它位于“A.X_PAGER_CO_ID = P.ROW_ID(+)”下面的行。 I am not sure what or how the (+) works.我不确定 (+) 是什么或如何工作的。 When I update this for MS SQL server it gives me a error because of the (+), when I take this out.当我为 MS SQL 服务器更新它时,当我取出它时,它给了我一个错误,因为 (+)。 My data set is different.我的数据集不同。 I do need to return the same data set in MS SQL Server as seen WITH the (+) in MS Access我确实需要在 MS SQL 服务器中返回与 MS Access 中的 (+) 相同的数据集

With (+) I see this data set (does not work in SQL Server):使用 (+) 我看到这个数据集(在 SQL 服务器中不起作用):

EMPLOYEEID|X_PAGER_CO_ID|ROW_ID   |PhoneNum
1-39T1L0  |1-3A3Z2E     |1-3A3Z2E |555-555-5555
1-39T1L0  |             |         |777-777-7777
1-39T1L0  |             |         |888-888-8888
1-39T1L0  |1-N0-3       |1-N0-3   |+AlphanumericPager 0000000000000 00000

With OUT (+) I see this data set (Does work in SQL Server):使用 OUT (+) 我看到了这个数据集(在 SQL 服务器中工作):

EMPLOYEEID|X_PAGER_CO_ID|ROW_ID   |PhoneNum
1-39T1L0  |1-3A3Z2E     |1-3A3Z2E |555-555-5555
1-39T1L0  |1-N0-3       |1-N0-3   |+AlphanumericPager 0000000000000 00000
A.PER_ID As EmployeeID,
A.X_PAGER_CO_ID,
P.ROW_ID,

  A.ADDR As PhoneNumber,
  A.COMM_MEDIUM_CD As DeviceType,
  A.X_ACTIVE_FLG As ActiveFlag,
  P.NAME As PagerCompanyName,
  P.PAGE_PH_NUM As PagerCompanyModem,
  P.X_SUPPORT_PH_NUM As PagerCompanySupport,
  A.X_PIN As PIN
FROM 
  xTrack.S_PER_COMM_ADDR A,
  xTrack.S_PAGER_COMPANY P
WHERE
  A.X_PAGER_CO_ID = P.ROW_ID(+) and
  A.PER_ID IN (SELECT 
                         E.PAR_ROW_ID 
                       FROM
                         xTrack.S_EMP_PER E,
                         xTrack.S_CONTACT C,
                         xTrack.S_BU SB,
                         xTrack.S_POSTN SP
                      WHERE
                         E.PAR_ROW_ID = C.PAR_ROW_ID AND
                         SP.BU_ID = SB.ROW_ID AND
                         C.PR_HELD_POSTN_ID = SP.PAR_ROW_ID)

AND A.PER_ID = '1-39T1L0'

that expression P.ROW(+) can't work in access and never could have.那个表达式 P.ROW(+) 不能在访问中工作,也永远不可能。 So, I would go back to the original query - that simply does not make sense.所以,我会 go 回到原来的查询 - 这根本没有意义。 I suspect that some kind of user defined function (UDF()) was being used in the original sql.我怀疑在原始 sql 中使用了某种用户定义的 function (UDF())。 So that is not actually a column name, but some kind of function.所以这实际上不是一个列名,而是某种 function。

You can fire up access and try any query with COLUMNNAME(+) and it will fail.您可以启动访问并尝试使用 COLUMNNAME(+) 进行任何查询,但它会失败。 So, you can't migrate something that don't work in Access.因此,您无法迁移在 Access 中不起作用的内容。 And until such time figure out what the original access sql looked like, then I am afraid your attempt at recreating the same query in SQL server will also fail.在弄清楚原始访问 sql 是什么样子之前,恐怕您在 SQL 服务器中重新创建相同查询的尝试也会失败。

That expression is not valid SQL in Access, so the issue is in the translation of the original Access sql - it is simply wrong or incorrect.该表达式在 Access 中无效 SQL,因此问题在于原始 Access sql 的翻译 - 它完全是错误的或不正确的。

It is possible that this was the column name so you would/should use:这可能是列名,因此您将/应该使用:

P.[ROW(+)] P.[行(+)]

In other words, for columns with spaces, funny characters, and reserved words (like "date" or "name" as a column name in access).换句话说,对于带有空格、有趣字符和保留字的列(如“日期”或“名称”作为访问中的列名)。 Such reserved words thus need a set of [] surrounding the column name.因此,此类保留字需要一组 [] 围绕列名。 I would look at the table design - see if there is a column named as such.我会看一下表格设计 - 看看是否有一个这样命名的列。

If yes, then try [] around the column name.如果是,则在列名周围尝试 []。 If the column name does not exist, then that sql simply could not have worked in Access.如果列名不存在,那么 sql 根本无法在 Access 中工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM