Join在Azure SQL中工作,但与R DBI连接失败:找不到多部分标识符



我有一个在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的组合,该查询查找给定main_id在t1中的最近条目。

不确定我的查询是否以糟糕的方式结构化,或者这是一个R问题。我试过根据我认为可能与stackoverflow其他地方相关的问题将SET NOCOUNT ON添加到查询中,但没有骰子。

我发现我的问题是什么了-我犯了一个愚蠢(但耗时)的错误…但本质上,我把我的SQL查询到R通过paste(scan(...), collapse = " ")。我在我的SQL查询中有一个评论,--,它不能被r正确读取。删除评论或将评论切换到/* ... */语法修复了这个问题。

最新更新