简体   繁体   中英

How to SQL Pass-through in SAS, create view or table

I am trying to create a View on the database through SAS, SQL passthrough the following way

PROC sql; 
CONNECT TO odbc AS myuser(dsn=galaxy);              
EXECUTE(
CREATE VIEW DB.SCHEM.table AS
    SELECT * FROM connection to myuser;
    (SELECT * FROM DB.SCHEM.table2)
)by myuser;
QUIT;

Howeever, I get the following errors

ERROR: CLI prepare error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword 'select'. : [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near ')'.

You have an extraneous SELECT * FROM connection to myuser; inside the EXECUTE. The code inside EXECUTE is submitted directly to SQL server, and your extraneous code is invalid.

Here is the SAS pass-through corrected. I would advise against using table as part of view name. Note: You will see an error message if your SQL Server credentials do not have the data base grants needed to create a view.

EXECUTE(
  CREATE VIEW DB.SCHEM.table AS
  SELECT * FROM DB.SCHEM.table2
) by myuser ;

From SQL Server docs for CREATE VIEW

 CREATE [ OR ALTER ] VIEW [ schema_name . ] view_name [ (column [ ,...n ] ) ] [ WITH <view_attribute> [ ,...n ] ] AS select_statement [ WITH CHECK OPTION ] [ ; ] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM