加入在 Azure SQL 中有效,但使用 R DBI 连接失败:找不到多部分标识符

Join works in Azure SQL but fails with with R DBI connection: The multi-part identifier could not be found

我有一个在 SSMS 中完美运行的查询。但是当 运行 使用 DBI 包在 R 中进行查询时,我收到几个多部分标识符错误:The multi-part identifier: "rt.secondary_id" could not be bound"rt.third_id" could not be bound"t2.important" could not be bound.

select t1.[main_id]
    ,rt.secondary_id
    ,rt.third_id
    ,t1.[date_col]
    ,t2.important
from t1
inner join rt on t1.main_id = rt.main_id
inner join t2 on rt.main_id = t2.main_id
inner join (select t1.main_id, max(t1.date_col) as upload_time from t1 group by t1.main_id) AS ag ON t1.main_id = ag.main_id AND t1.date_col = ag.upload_time

t1 中的唯一标识符是 main_iddate_col 的组合,此查询查找 t1 中给定 main_id.

的最新条目

不确定我的查询是否结构不当或者这是一个 R 问题。我已经尝试根据我认为可能与 Whosebug 上其他地方相关的问题将 SET NOCOUNT ON 添加到查询中,但没有骰子。

我发现我的问题是什么——我犯了愚蠢(但耗时)的错误……但本质上,我是通过 paste(scan(...), collapse = " ") 将我的 SQL 查询带入 R。我在 SQL 查询 -- 中有一条评论,R 无法正确读取它。删除评论或将评论切换为 /* ... */ 语法可以解决问题。