I'm trying to pull data through BigQuery stored procedure in SAS. Here is my code:
proc sql;
&bq_connection;
create table test as
select * from connection to &bq_conn_name
(
CALL `project.schema.stp_name`();
);
quit;
The stored procedured works fine in GCP console, but I'm error the below error in SAS:
ERROR: CLI prepare error: Message text truncated.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
Any help would be appreciated!!
Thanks.
Related
Here is the stored procedure and how I created it
CREATE OR REPLACE STORED PROCEDURE SimpleSelect()
AS
BEGIN
SELECT * FROM Permissions
END;
/
CALL SimpleSelect();
When creating the procedure I get the error
"Success with some compilation errors"
and when running the CALL command I get that the SQL command not properly ended.
It is important to know which database do you use. Some of this advice's will come in handy in many databases but some will not...
Do you have a table called Permissions already created ? If not, create it.
Please put a ; after the SELECT statement. Like this:
SELECT * FROM Permissions;
In MySQL this will not return error:
CREATE PROCEDURE SimpleSelect()
BEGIN
SELECT * FROM Permissions;
END;
/
When you fix your procedure the call command will work just fine...
Cheers!
Here is the DEMO
I have a stored procedure that I often execute within SQL Server. Without copying hundreds of lines of code into here, it basically does the following:
You enter a database and table name as parameters.
The procedure then calculates summary statistics on all fields in the table (average, sum etc.) and inserts them into a temporary table.
The summary statistics are then inserted into an existing meta table.
The temporary table of stats is then dropped.
The procedure itself works perfectly when executing through SQL Server.
However, executing the same procedure with the same parameters through SAS code (via WPS) does not return the same results. It kicks off the procedure and calculates the statistics, but then fails to insert the statistics into the existing table and fails to drop the temporary table. Despite this, no errors are returned in the SAS log. The SAS code to execute the procedure is here:
proc sql;
connect to odbcold(required="dsn=&SQLServer; database=_Repository;");
execute (SP_Meta_Stats
#DATABASE = &vintage.,
#TABLE_NAME = &table_name.) by odbcold;
disconnect from odbcold;
quit;
I can assure you the macro variables have been setup correctly because the procedure is kicking off correctly with the correct parameters. It's just not completing the procedure as it does directly in SQL.
Are there are any known limitations to executing SQL stored procedures through a proc sql statement in SAS? Any known reasons why this not be computing the same as it does in SQL, despite just executing the same procedure?
EDIT:
This seems to be some sort of connection issue. As if after a certain time lapses, WPS disconnects from the SQL connection. Because sometimes the temporary table has only computed stats for a handful of variables.
For the below stored procedure in Teradara DB, I am able to crate it when running it as a sql statement. But when I am trying to run it through SQl script file, it's not getting created and throws error messgae:
SQL Error [5526] [HY000]: [Teradata Database] [TeraJDBC 15.00.00.33] [Error 5526] [SQLState HY000] Stored Procedure is not created/replaced due to error(s).
CREATE PROCEDURE SCHEMA.SELECT_PROCEDURE(IN ROLL_ INTEGER,OUT MARKS_
FLOAT)
DYNAMIC RESULT SETS 1
BEGIN
SELECT MARKS INTO MARKS_ FROM SCHEMA.TEST WHERE ROLL = :ROLL_;
END;
I have also searched the error on internet, but didn't get much help.
Help here, please !
Here is my code:
PROC SQL;
connect to odbc (dsn=ODC uid=sa pwd=XXXXX);
EXECUTE ( INSERT INTO dbo.tblDLA_Backup SELECT * FROM &dlafile.) BY ODBC;
disconnect from odbc;
quit;
Im getting this error
ERROR: CLI execute error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'work.dlabackup'.
If i do this:
proc sql;
connect to odbc (dsn=ODC uid=sa pwd=XXXXX);
insert into tblDLA_Backup SELECT * FROM WORK.DLABACKUP;
disconnect from odbc;
quit;
I get this error:
ERROR: File WORK.TBLDLA_BACKUP.DATA does not exist.
Why is it that I can't reference my SAS dataset and just insert? it should be simple as that..
The first error occurs because you are executing an SQL instruction on SQL Server, and not locally. And since this instruction contains a reference to your local SAS dataset, an error occurs because SQL server thinks it is a table in its own database.
You take a wrong approach on that one.
Your second approach is correct because you are executing the SQL in SAS, which both knows the local dataset and the SQL server tables. And it is syntactically valid at first glance.
The error is clear: SAS doesn't found the local dataset WORK.TBLDLA_BACKUP
Thus, verify if this dataset exists and is not corrupted:
in your explorer window, click on Libraries, then Work, and verify if TBLDLA_BACKUP is there, and if yes open it and check if you see your data.
I can't say more at this point, but you should hopefully discover something.
You need to use libref it you want to write into the foreign database.
libname sqldb odbc dsn=ODC uid=sa pwd=XXXXX ;
PROC SQL;
INSERT INTO SQLDB.tblDLA_Backup SELECT * FROM &dlafile.;
quit;
Note that you also need fix it so that your macro variable contains the name of a table that exists.
I've made a database and I'm trying to make some stored procedures for it,
I added a new query file to my database and i wrote the following code in it,
create procedure SEL_STUDENT
as
begin
select * from student
end
execute SEL_STUDENT
go
But anytime i try to execute the following line
execute SEL_STUDENT
it returns an error, saying,
Msg 2812, Level 16, State 62, Line 53
Could not find stored procedure 'SEL_STUDENT'
Please help me fix it.
Thanks.
I ran your code using a table from the AdventureWorks2012 database.
create procedure SEL_STUDENT
as
begin
select * from [Person].[Person]
end
go
execute SEL_STUDENT
And it works fine.
Although I have moved GO above execute SEL_STUDENT that is not the issue here as #CoOl points out because you specifically say you execute the stored procedure after your block of code.
The only possible explanation would be that you are querying execute SEL_STUDENT on the wrong database.
Try the following code -
USE [DatabaseName]
GO
execute SEL_STUDENT
Here, [DatabaseName] is the database where the stored procedure SEL_STUDENT table is stored.
Make sure your table is also stored in the same database or else you would have to modify select * from student to select * from [DatabaseName].[SchemaName].[student]
Additionally, you can use the Object Explorer to identify where your stored procedure has been saved. I am unable to post a snapshot of how to do this as my reputation is below 10.
EDIT : Now that my reputation is in two digits -
Kindly note that [dbo] is the default schema in SQL Server.
Because you are trying to execute the Stored Procedure which is not there yet.
Move GO above execute SEL_STUDENT
create procedure SEL_STUDENT
as
begin
select * from student
end
go
execute SEL_STUDENT