SQL R 中的脚本仅提供有限数量的观察
SQL script in R giving only limited number of observation
我正在 运行在 R Studio 中编写 SQL 脚本并连接到 SAP HANA 服务器。每次,我 运行 脚本只给我有限的观察。有时,我会得到 800 个观察结果,有时会得到 1000 个观察结果。
当 运行 在 Tableau 或 SSMS 中使用此 SQL 脚本时,我得到了百万次观察。
谁能帮忙,为什么 R 只给出有限的行?
下面是我使用的代码
library(RODBC)
ch <- odbcConnect('HANAxxx',uid='xxxxx',pwd='xxxxx', DBMSencoding="UTF-8")
fiscqtr <- as.character(20191)
begqtr <- as.character(201901)
endqtr <- as.character(201913)
avginvBOP <- as.character(201850)
avginvEOP <- as.character(as.numeric(endqtr)-1)
eopweek <- endqtr
receiptstart <- as.character(201850)
receiptend <- as.character(as.numeric(endqtr)-2)
sales <- sqlQuery(ch, paste('SELECT
mat."DIVISION_TXT" AS Division_Name,
mat."DEPARTMENT_TXT" AS Department_Name,
mat."CLASS_TXT" AS Class_Name,
mat."yz_abc1" AS Base_Style_ID,
mat."yz_abc1_TXT" AS Base_Style_Name,
mat."COLOR" AS Color_Code,
mat."COLOR_TXT" AS Color_Name,
SUM(CASE WHEN (r."ZWEEK" BETWEEN \'',begqtr,'\' AND \'',endqtr,'\') THEN r."SALES" ELSE 0 END) AS NET_SLS$,
SUM(CASE WHEN (r."ZWEEK" BETWEEN \'',begqtr,'\' AND \'',endqtr,'\') THEN r."COST" ELSE 0 END) AS NET_SLSC,
SUM(CASE WHEN (r."ZWEEK" BETWEEN \'',begqtr,'\' AND \'',endqtr,'\') THEN r."UNIT" ELSE 0 END) AS NET_SLSU,
SUM(CASE WHEN (r."ZWEEK" = \'',eopweek,'\') THEN r."ONHAND" ELSE 0 END) AS EOP_INV_UNIT,
SUM(CASE WHEN (r."ZWEEK" = \'',eopweek,'\') THEN r."ONHANDCOST" ELSE 0 END) AS EOP_INV_COST,
AVG(CASE WHEN (r."ZWEEK" BETWEEN \'',avginvBOP,'\' AND \'',avginvEOP,'\') THEN r."ONHAND" ELSE 0 END) AS BOP_INV_UNIT,
AVG(CASE WHEN (r."ZWEEK" BETWEEN \'',avginvBOP,'\' AND \'',avginvEOP,'\') THEN r."ONHANDCOST" ELSE 0 END) AS BOP_INV_COST,
SUM(CASE WHEN (r."ZWEEK" BETWEEN \'',receiptstart,'\' AND \'',receiptend,'\') THEN r."RECEIPU" ELSE 0 END) AS RECEIPT_UNITS,
SUM(CASE WHEN (r."ZWEEK" BETWEEN \'',receiptstart,'\' AND \'',receiptend,'\') THEN r."RECEIPC" ELSE 0 END) AS RECEIPT_COST
FROM "_SYS_BIC"."ZBHD.bw.bw2hana/XYZ_REPORT" As r
LEFT JOIN "_SYS_BIC"."ZBHD.bw.bw2hana/XYZ_MASTERMATERIAL" As mat On r."0MATERIAL" = mat."MATERIAL"
WHERE mat."DIVISION" IN (\'A\',\'B\',\'C\',\'D\',\'E\')
AND mat."MATL_TYPE" = \'RECENT\'
GROUP BY
mat."DIVISION_TXT",
mat."DEPARTMENT_TXT",
mat."CLASS_TXT",
mat."yz_abc1",
mat."yz_abc1_TXT",
mat."COLOR",
mat."COLOR_TXT"', sep = ''))
我其实通过安装RJDBC包和安装jdbcDriver解决了一个错误。它工作得很好......谢谢你的帮助。
下面是安装驱动和连接HANA的代码
jdbcDriver <- JDBC(driverClass="com.sap.db.jdbc.Driver", classPath="C:/Program Files/sap/hdbclient/ngdbc.jar")
ch <- dbConnect(jdbcDriver,"jdbc:sap://servername:port","username","password")
我正在 运行在 R Studio 中编写 SQL 脚本并连接到 SAP HANA 服务器。每次,我 运行 脚本只给我有限的观察。有时,我会得到 800 个观察结果,有时会得到 1000 个观察结果。 当 运行 在 Tableau 或 SSMS 中使用此 SQL 脚本时,我得到了百万次观察。
谁能帮忙,为什么 R 只给出有限的行?
下面是我使用的代码
library(RODBC)
ch <- odbcConnect('HANAxxx',uid='xxxxx',pwd='xxxxx', DBMSencoding="UTF-8")
fiscqtr <- as.character(20191)
begqtr <- as.character(201901)
endqtr <- as.character(201913)
avginvBOP <- as.character(201850)
avginvEOP <- as.character(as.numeric(endqtr)-1)
eopweek <- endqtr
receiptstart <- as.character(201850)
receiptend <- as.character(as.numeric(endqtr)-2)
sales <- sqlQuery(ch, paste('SELECT
mat."DIVISION_TXT" AS Division_Name,
mat."DEPARTMENT_TXT" AS Department_Name,
mat."CLASS_TXT" AS Class_Name,
mat."yz_abc1" AS Base_Style_ID,
mat."yz_abc1_TXT" AS Base_Style_Name,
mat."COLOR" AS Color_Code,
mat."COLOR_TXT" AS Color_Name,
SUM(CASE WHEN (r."ZWEEK" BETWEEN \'',begqtr,'\' AND \'',endqtr,'\') THEN r."SALES" ELSE 0 END) AS NET_SLS$,
SUM(CASE WHEN (r."ZWEEK" BETWEEN \'',begqtr,'\' AND \'',endqtr,'\') THEN r."COST" ELSE 0 END) AS NET_SLSC,
SUM(CASE WHEN (r."ZWEEK" BETWEEN \'',begqtr,'\' AND \'',endqtr,'\') THEN r."UNIT" ELSE 0 END) AS NET_SLSU,
SUM(CASE WHEN (r."ZWEEK" = \'',eopweek,'\') THEN r."ONHAND" ELSE 0 END) AS EOP_INV_UNIT,
SUM(CASE WHEN (r."ZWEEK" = \'',eopweek,'\') THEN r."ONHANDCOST" ELSE 0 END) AS EOP_INV_COST,
AVG(CASE WHEN (r."ZWEEK" BETWEEN \'',avginvBOP,'\' AND \'',avginvEOP,'\') THEN r."ONHAND" ELSE 0 END) AS BOP_INV_UNIT,
AVG(CASE WHEN (r."ZWEEK" BETWEEN \'',avginvBOP,'\' AND \'',avginvEOP,'\') THEN r."ONHANDCOST" ELSE 0 END) AS BOP_INV_COST,
SUM(CASE WHEN (r."ZWEEK" BETWEEN \'',receiptstart,'\' AND \'',receiptend,'\') THEN r."RECEIPU" ELSE 0 END) AS RECEIPT_UNITS,
SUM(CASE WHEN (r."ZWEEK" BETWEEN \'',receiptstart,'\' AND \'',receiptend,'\') THEN r."RECEIPC" ELSE 0 END) AS RECEIPT_COST
FROM "_SYS_BIC"."ZBHD.bw.bw2hana/XYZ_REPORT" As r
LEFT JOIN "_SYS_BIC"."ZBHD.bw.bw2hana/XYZ_MASTERMATERIAL" As mat On r."0MATERIAL" = mat."MATERIAL"
WHERE mat."DIVISION" IN (\'A\',\'B\',\'C\',\'D\',\'E\')
AND mat."MATL_TYPE" = \'RECENT\'
GROUP BY
mat."DIVISION_TXT",
mat."DEPARTMENT_TXT",
mat."CLASS_TXT",
mat."yz_abc1",
mat."yz_abc1_TXT",
mat."COLOR",
mat."COLOR_TXT"', sep = ''))
我其实通过安装RJDBC包和安装jdbcDriver解决了一个错误。它工作得很好......谢谢你的帮助。
下面是安装驱动和连接HANA的代码
jdbcDriver <- JDBC(driverClass="com.sap.db.jdbc.Driver", classPath="C:/Program Files/sap/hdbclient/ngdbc.jar")
ch <- dbConnect(jdbcDriver,"jdbc:sap://servername:port","username","password")