未创建 SQL Server 中的表,代码从 R 运行

Table in SQL Server is not created, code is run from R

提问人:Rita 提问时间:11/8/2023 最后编辑:Rita 更新时间:11/9/2023 访问量:60

问:

我正在尝试从 R 运行 SQL Server 代码,但未创建我的表。SQL 代码具有在 SQL Server 中创建表的左联接。如果删除左联接,则会创建表,但当我引入左联接时,不会创建表。代码运行后我也没有收到任何错误。

我尝试在 SQL 代码的 select 语句中显式命名列,但没有任何反应。R 和左连接实际上存在问题吗?

这是 SQL 中的代码的样子

drop table if exists [Raise_Replacement].[SchoolContextual].[NationalCharacteristicsBasic_<this_yr>_working_Auto] 
    select a.[TabOrder], a.[Measure], a.[national_y3], b.[national_y3] as [national_y2], b.[national_y2] as [national_y1] , a.[Phase]
    into [Raise_Replacement].[SchoolContextual].[NationalCharacteristicsBasic_<this_yr>_working_Auto] 
    from #natbasicchars a
    left join [Raise_Replacement].[SchoolContextual].[NationalCharacteristicsBasic_<last_yr>] b
    on (a.TabOrder=b.TabOrder) and (a.phase=b.Phase)

我在R代码中有:

    #define libraries and packages
    library(dplyr)
    
    # UPDATE THESE LINES - Most recent and last year value to pull in
    last_yr <- "2022" # Used in sql script.
    this_yr <- "2023"

这个 R 和 SQL 接口使我们每年只能更新几行代码。我还有读取SQL代码的代码:

      basic_characteristic_trends_code <- gsub(paste0("<this_yr>"),this_yr, basic_characteristic_trends_code)
      basic_characteristic_trends_code <- gsub(paste0("<this_yr_file_short>"),this_yr_file_short, basic_characteristic_trends_code)
     
      # Run the SQL code -----------------------------------------------
      dbGetQuery(con, statement = basic_characteristic_trends_code)

另外,请注意,当我运行代码时没有错误。

r sql-server 左联接

评论


答: 暂无答案