Proc SQL 未返回任何列。内部联接
Proc SQL not returning any columns. Innerjoin
我正在尝试收集有关哪个商店正在接收哪个 SKU 的信息以及其他一些相关信息。数据在多个 table 中,所以我正在尝试 innerjoin 信息。我正在使用 SAS,它通过直通在 SQL 服务器中 运行s。下面是我试过的查询。我已经确认 ||在传递中工作。问题似乎始于 from 语句
connect to odbc (dsn='X' uid='X' pwd='XY');
create table School.TRANS_INFO as SELECT * from connection to odbc
(SELECT Distinct
S.Schd_t AS Schd_Date format MMDDYY10.,
S.otb As Ship_Loc,
W.store_NUMBER AS store,
S.SHP_ID AS SHIP_ID,
W.store_CITY_STATE,
Q.Stat_CD AS Status,
(S.PROD_CD || S.plt_CD) AS SKU,
W.ACCOUNT_TYPE as Location
FROM
SHPMT_DTL S
INNER JOIN store W ON W.store_NUMBER = S.Otb_DEST_store_NBR,
INNER JOIN SHP_LEG Q ON Q.SHPMT_ID = S.SHP_ID
WHERE
W.ACCOUNT_TYPE = 'I'
AND S.Schd_t <= Sysdate
AND Q.Stat_CD IN ('S','P')
ORDER BY Schd_Date);
disconnect from odbc;
QUIT;
但是,在我 运行 之后,我收到一条错误消息“PROC SQL 要求任何已创建的 table 至少有 1 列”。任何诊断此问题的帮助将不胜感激。
将 SAS 语法移至查询的 SAS 端。 FROM 子句中间还有一个额外的逗号。请注意,如果您养成将逗号(或任何其他连续字符)放在行首而不是末尾的习惯,程序员将更容易扫描并确保它们正确完成。
create table School.TRANS_INFO as
SELECT Distinct
Schd_t AS Schd_Date format MMDDYY10.
, otb As Ship_Loc
, store_NUMBER AS store
, SHP_ID AS SHIP_ID
, store_CITY_STATE
, Stat_CD AS Status
, (PROD_CD || plt_CD) AS SKU
, ACCOUNT_TYPE as Location
from connection to odbc
(SELECT Distinct
S.Schd_t
, S.otb
, W.store_NUMBER
, S.SHP_ID
, W.store_CITY_STATE
, Q.Stat_CD
, S.PROD_CD
, S.plt_CD
, W.ACCOUNT_TYPE
FROM SHPMT_DTL S
INNER JOIN store W ON W.store_NUMBER = S.Otb_DEST_store_NBR
INNER JOIN SHP_LEG Q ON Q.SHPMT_ID = S.SHP_ID
WHERE W.ACCOUNT_TYPE = 'I'
AND S.Schd_t <= Sysdate
AND Q.Stat_CD IN ('S','P')
ORDER BY S.Schd_t
);
我正在尝试收集有关哪个商店正在接收哪个 SKU 的信息以及其他一些相关信息。数据在多个 table 中,所以我正在尝试 innerjoin 信息。我正在使用 SAS,它通过直通在 SQL 服务器中 运行s。下面是我试过的查询。我已经确认 ||在传递中工作。问题似乎始于 from 语句
connect to odbc (dsn='X' uid='X' pwd='XY');
create table School.TRANS_INFO as SELECT * from connection to odbc
(SELECT Distinct
S.Schd_t AS Schd_Date format MMDDYY10.,
S.otb As Ship_Loc,
W.store_NUMBER AS store,
S.SHP_ID AS SHIP_ID,
W.store_CITY_STATE,
Q.Stat_CD AS Status,
(S.PROD_CD || S.plt_CD) AS SKU,
W.ACCOUNT_TYPE as Location
FROM
SHPMT_DTL S
INNER JOIN store W ON W.store_NUMBER = S.Otb_DEST_store_NBR,
INNER JOIN SHP_LEG Q ON Q.SHPMT_ID = S.SHP_ID
WHERE
W.ACCOUNT_TYPE = 'I'
AND S.Schd_t <= Sysdate
AND Q.Stat_CD IN ('S','P')
ORDER BY Schd_Date);
disconnect from odbc;
QUIT;
但是,在我 运行 之后,我收到一条错误消息“PROC SQL 要求任何已创建的 table 至少有 1 列”。任何诊断此问题的帮助将不胜感激。
将 SAS 语法移至查询的 SAS 端。 FROM 子句中间还有一个额外的逗号。请注意,如果您养成将逗号(或任何其他连续字符)放在行首而不是末尾的习惯,程序员将更容易扫描并确保它们正确完成。
create table School.TRANS_INFO as
SELECT Distinct
Schd_t AS Schd_Date format MMDDYY10.
, otb As Ship_Loc
, store_NUMBER AS store
, SHP_ID AS SHIP_ID
, store_CITY_STATE
, Stat_CD AS Status
, (PROD_CD || plt_CD) AS SKU
, ACCOUNT_TYPE as Location
from connection to odbc
(SELECT Distinct
S.Schd_t
, S.otb
, W.store_NUMBER
, S.SHP_ID
, W.store_CITY_STATE
, Q.Stat_CD
, S.PROD_CD
, S.plt_CD
, W.ACCOUNT_TYPE
FROM SHPMT_DTL S
INNER JOIN store W ON W.store_NUMBER = S.Otb_DEST_store_NBR
INNER JOIN SHP_LEG Q ON Q.SHPMT_ID = S.SHP_ID
WHERE W.ACCOUNT_TYPE = 'I'
AND S.Schd_t <= Sysdate
AND Q.Stat_CD IN ('S','P')
ORDER BY S.Schd_t
);