SET NOCOUNT ON for google bigquery - ms-access

I'm trying to run a pass-through query on MS Access via BigQuery ODBC. Here is the simple query:
begin
create temp table table2 as(
select * from table1
);
end;
select * from table2;
After googling around a bit, it seems like MS Access stops the query after temp tables are created. As such this returns no results. The workaround to this to set nocount on. Does such functionality exist in BigQuery?
Thank you

Related

How to execute a stored statement in a stored procedure

I'm creating a function in mySQL that will update table metrics each time the any table has something inserted or deleted from it. So I've got my Table_metrics table, with elements table_name and row_count:
CREATE TABLE Table_metrics (
table_name VARCHAR(64),
row_count INTEGER DEFAULT 0 );
So any time something gets added to any of my tables (other than this one) in the database the matching row gets updated with the number of rows in that table.
To do this I've tried making a stored procedure:
CREATE PROCEDURE table_update_metric(IN tablename VARCHAR(64))
UPDATE Table_metrics
SET row_count=(SELECT COUNT(*) FROM tablename)
WHERE table_name = tablename;
This produces an error when I call the procedure call table_update_metric('Owners'); (Owners being a table in my database)
table DB.tablename doesn't exist
I've done a bit of digging into stored procedures, trying to figure out how they would work. I assume the issue is coming from the line `SELECT COUNT(*) FROM tablename), so I tried having a stored statement in the procedure:
CREATE PROCEDURE table_update_metric(IN TABLENAME VARCHAR(64))
SET #s = CONCAT('SELECT COUNT(*) FROM ', tablename)
UPDATE Table_metrics
SET row_count=EXECUTE #s
WHERE table_name = tablename;
I'm not really sure how to properly do a stored statement as I'm still relatively new to mySQL, but I believe that it's the way to go.
Can anyone offer any insight into this problem?
What you are trying to do is already provided in Mysql. Information Schema Tables stores this information for you :)
SELECT TABLE_NAME, TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '{your_db}';
From what Somonare said, I created a table in my database that uses that information:
CREATE TABLE Table_metrics
SELECT TABLE_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'Sensors';
And this table will be updated with a trigger each time the tables in Sensors are updated.

Is It possible to return Multiple tables from stored proc in MYSQL

I am want to return two tables from one Stored Proc. I am not sure if it is possible or not, but it is possible in MSSQL, so, I guess it is possible in MYSQL as well.
What I want to achieve is:
select * from table1;
select * from table2;
result in dataset of two tables. As I experienced till now, where MYSQL get's the first select it returns from there.
I have tried to find on Google, but I didn't find anything that works.
Yes, you can return as many result sets as you like.
delimiter $$
create procedure sp_result_sets()
begin
select * from table1;
select * from table2;
end
$$

MySql - Create a table and select from it in the same procedure

I’m trying to execute this simple code as a procedure in MySql using the PHPMyAdmin
CREATE TEMPORARY TABLE IF NOT EXISTS jobs AS (SELECT
*
FROM
all_jobs
WHERE
job_object_type LIKE 'jobName'
OR
job_object_type LIKE 'jobStatus');
SELECT
*
FROM
jobs
But I’m getting an error (#1064) because of my second SELECT query. I’m coming from MS-SQL and there the SELECT would be executed without any problems. How can I execute the CREATE TABLE X query and direct after that the SELECT * FROM X query in the same procedure?
EDIT: forgot to mention that I’m using the MariaDB
Well that is how it's done using the PHPMyAdmin:
BEGIN
CREATE TEMPORARY TABLE IF NOT EXISTS jobs AS (SELECT
*
FROM
all_jobs
WHERE
job_object_type LIKE 'jobName'
OR
job_object_type LIKE 'jobStatus');
SELECT
*
FROM
jobs;
END
Now everything is being executed as it should be.

MySQL using routine output to join on table

I have a routine that is called using
SET #p0='55'; SET #p1='-6'; SET #p2='100'; CALL `distanceSearch`(#p0, #p1, #p2);
Basically i pass in latitude, longitude and a distance to search for users, e.g 100 miles. The routine creates a temp table and inserts results into it. When i execute it, a result set is returned.
When i try execute it like this i run into a syntax error
SET #p0='55'; SET #p1='-6'; SET #p2='100';
select foo.* from (CALL `distanceSearch`(#p0, #p1, #p2)) as foo
What am i doing wrong? How do use the results from this to join on another table?
NO, you can't perform a select from procedure like that way but as you said The routine creates a temp table and inserts results into it
in that case if you already know the temporary table name then do a SELECT from that table
select * from temporary_table_name
Else, convert your routine to a table valued function rather than a stored procedure and then you can say
select * from fn_runRoutine_Job()

How to call SPs with #temp using OpenRowSet in a View?

I am trying to run a stored procedure from an application which supports connecting to only tables and views. My work around was to use a view which gets results from SP via Openrowset(). Turns out that the SP is using #temp tables to store intermediate results and this is a DDL operation which seems to be not supported for distributed queries. I can replace #temp with #temp table variables but it slowing down the whole code drastically (I was using bulk insert (select * into #temp from t1) to speed up things).
The error message I am getting is
Cannot process the object "exec
DW.dbo.TestSpWithTempTable".
The OLE DB provider "SQLNCLI10" for linked server "(null)" indicates
that either the object has no columns or the current user does not
have permissions on that object.
Is there anyway I can use #temp tables in an SP and call it from a view using OpenRowSet?
CREATE PROC TestSpWithTempTable
AS
Select distinct TxnType into #txnTypes from Transactions
-- lot of other stuffs going on here
select TxnType from #temp
GO
The view I created is:
CREATE VIEW SelectDataFromSP
SELECT a.*
FROM OPENROWSET('SQLNCLI', 'Server=(local);TRUSTED_CONNECTION=YES;',
'exec DW.dbo.TestSpWithTempTable') AS a
The code that works but slow is
CREATE PROC TestSpWithTempTable
AS
declare #TxnTypes table(TxnType varchar(100))
insert into #TxnTypes
Select distinct TxnType from Transactions
-- lot of other stuffs going on here
select TxnType from #TxnTypes
GO