Can datasource of a report by a big query procedure? - google-bigquery

Can the datasource of a google datastudio report come from a bigquery procedure?
If so how?
So far, I've tried calling the procedure from a "Custom Query" like so :
CREATE OR REPLACE PROCEDURE `EDL-DEMO.DatasetDemo.Test`(paramSample1 STRING, paramSample2 INT64)
BEGIN
SELECT *
FROM `EDL-DEMO.DatasetDemo.someView`;
END;
This attempt gave : Error ID: 7b7e7776
Another work around that might be possible would be to use temporary table, but at this point, I will probably step away from procedure instead.

Another option is to use a scheduled query to invoke the procedure on a defined interval, and point the data studio report at the output table(s) generated by the procedure.
This may have been what you were alluding to with the temporary table comment. It's largely a question of the complexity of the procedure; in your example case you could avoid the procedure entirely and do a scheduled CREATE OR REPLACE TABLE ... AS SELECT ... query.

Related

What can I do instead execute stored procedure in sql server function

In a select statement I am calling a function which I should show result of it in the result table of select statement. In this function, I need to recreate (it is just checking actually if it is necessary to be recreated or not then it will recreate if necessary) a table which the function uses and I know I can not do that in a function so I created a stored procedure to recreate the table.
I can not exec stored procedure before the select statement because I need to do that in every row. Because the content of the table may need to be changed according to parameters of it every time.
But I know that I also can not exec a stored procedure within a function because of this error Only functions and some extended stored procedures can be executed from within a function. So in final situation, I need to exec stored procedure in a function in order to recreate the table or I need to create a non-temporary table in a function. I could not find any solution for this. Is there any solution to do that in a different way?
I am trying to explain what am I trying to do in details. The table that I mentioned above, stores a list of start times and end times of some workers. In the function I am using this time informations and doing something with it.
But In my select statement I am sending a time parameter to the funciton and this time can be old, for example a month ago. And start and end hours of workers can be different at a month ago. So in this situation according to time parameter of the function I may need to recreate the table. But I can not do that in a function so I did it in a stored procedure but I can not exec this stored procedure in a function as well. And I also can not create a table in the function.

Manipulating data from a stored procedure by saving data into a table

Problem: I have a stored procedure in SQL Server 2012 and I want to put constraints to the output so I only get relevant information.
I am using Execute. The way I see it I have two options:
save the result of the execution into a table, so I can use it for different purposes
put constraints to the variables in Execute so I only get the results I want
The first method is discussed here:
Insert results of a stored procedure into a temporary table .
My code is (due to company information I can't share the whole thing):
create table #mtable ( .... )
Insert into #mtable
Execute [myProcedure]
The error:
An INSERT EXEC statement cannot be nested.
I assume the error is because of the code in the stored procedure. How can I fix that problem without looking into the code for the stored procedure. Is there another way where I can save the content in a table?
My problem can also be solved by proposal #2. Is it possible for me to manipulate the output from the stored procedure with something like:
Execute [myProcedure] where variable1 > 100

How to call a stored procedure within a SELECT query?

I have a store procedure that takes in a uniqueidentifier and returns a table. What I am trying to do is to use these results like a regular table, but I realize SQL is still limited and doesn't allow it (yet!)
Example:
SELECT *
FROM MyTable MT
WHERE NOT EXISTS
(SELECT *
FROM MyStoredProc(MT.ID) MSP
WHERE MT.SomeData = MSP.SomeData)
Is there an alternative solution to this problem? And please don't suggest using a function or a view as they are not exchangeable with a stored procedure. I'm actually quite surprised that the developers haven't implemented this yet considering the age of SQL.
Any help would be really appreciated!
That syntax won't work. You'd have to dump the results of the stored proc into a temp table and the reference the temp table.
Because Of the parameter, I'd suggest either making a new version of the proc that can execute for all IDs at once or drop the proc code into a table valued function (which can be executed using the syntax you're trying to use).

How should I select or display the out variable from a stored procedure call?

I'm writing a pretty basic stored procedure that just takes values from the sample DB2 database and computes the standard deviation. I wrote the procedure itself just fine, and I can call it without error. But I can't figure out how to actually display my result or select it in a statement. Everything I try results in a syntax error and I haven't been able to find anyone doing this specific task in my google searches.
This is the gist of my code (snipped for brevity):
CREATE PROCEDURE SAL_STD_DEV
(OUT std_dev real)
LANGUAGE SQL
BEGIN
--do stuff
SET std_dev = 10; --changed for simplicity
END#
CALL SAL_STD_DEV(?)#
All this runs, but just CALL doesn't create any output. What's the syntax to SELECT the out variable? I can't put a DECLARE before the CALL because it's not in a stored procedure, and PRINT doesn't work either.
(# is my terminal character because I'm using ; in the stored procedure)
Edit: Both the create procedure and call statements are made in the same SQL file, the database is connect to through localhost and I'm using DB2 11.1.0.1527 and developing in IBM Data Studio 4.1.2.
From wherever the CALL is being made, that feature might present a Result Set, despite apparently not presenting the result of an OUT parameter. If so, then the stored procedure perhaps could be revised to return the OUT value [instead, or additionally] as a result set, so that the interface that accepts the CALL statement as input, might present that result-set. Regardless:
In a statement processor [e.g. that is not a GUI, but] for which SELECT query output is presented, the following scripted requests should likely suffice:
create variable my_real real
;
call SAL_STD_DEV(my_real)
;
select my_real from sysibm.sysdummy1
;

Temporary table in stored procedure

I have a stored procedure that executes variously dynamic sql statements.
In reality this Stored procedure will be fired from SSIS with various parameters.
So there will be a lot of parallel executions.
This stored procedure uses temp tables during execution.
I create the tables manually with a Select .. into statement and drop them at the end.
During parallel executions, the process ends up in error because of execution 2 is trying to create or use the same temp table as execution 1. This is giving errors..
I tried to resolve this using table variables. However this does not work in dynamic SQL. (How to use table variable in a dynamic sql statement?)
I tried to resolve this using local temp table. However SSIS and Stored Procedures using local temp tables is not a great marriage. I have never found a good working solution so far.. http://consultingblogs.emc.com/jamiethomson/archive/2006/12/20/SSIS_3A00_-Using-stored-procedures-inside-an-OLE-DB-Source-component.aspx
I have an idea of how to create a temp table with the name of a GUID. And then use this so that it is unique in the Stored Procedure execution. However this would really make my dynamic SQL code much more difficult to maintain.
Does anyone see other options or am I over-complicating things? Is there a more viable solution?
You can create the temp table as
Create table #tmp_execute
(
id int,
name varchar(50),
.......
)
then, execute the dynamic query
insert into #tmp_execute
select .... from tbl_Sample
If you are require to execute the dynamic columns, you can use ' alter table #tmp_execute add your_column int' with conditional statement.