Error while connecting to stored procedure in Tableau - tableau-desktop

I'm getting this error while trying to connect to a stored procedure as data source:
Unable to complete action
The stored procedure returned no results. The fields don't have column names, or the data in the fields is not a supported data type
But the same stored procedure returns data in database. Any idea on this?

Please try adding the SET NOCOUNT ON code in the beginning of the stored procedure.
Something like
CREATE PROCEDURE [dbo].[ZZZ_THIS_IS_MY_SP]
#p INT
AS
BEGIN
SET NOCOUNT ON
DECLARE #Var1 NVARCHAR(20)
DECLARE #Var2 DATETIME
-- All other instructions...
END

Related

How to write correct stored procedure in netezza to fetch and display all records from table ? need select procedure

I have written a stored procedure for select operation in netezza db, but its throwing error while I try to execute that stored procedure.
Below is my stored procedure for select operation to fetch and display all records from a table.
#delimiter %%%;
CREATE OR REPLACE PROCEDURE return_result10() RETURNS REFTABLE(tbl)
LANGUAGE NZPLSQL AS
BEGIN_PROC
BEGIN
call * from tbl;
RETURN REFTABLE;
END;
END_PROC;%%%
#delimiter;%%%
I am getting below error as soon as I try to execute this using command ( execute PROCEDURE return_result10(); )
[Code: 1100, SQL State: HY000] ERROR: query "SELECT * from tbl" didn't return a single value
I want a stored procedure to fetch and display all records present in a table in netezza db.

HSQL problem when using TIMESTAMP value as IN parameter in stored procedure

Overview HSQL IN parameter of type TIMESTAMP doesn't work as expected for HSQL stored procedure.
Given the following DDL :
CREATE TABLE TS_STORE (
ID_COL VARCHAR(20) NOT NULL PRIMARY KEY,
TS TIMESTAMP
);
A DML statement such as :
INSERT INTO TS_STORE (ID_COL, TS) VALUES ('key1', '2020-02-19 12:17:53');
will successfully insert a row.
Then when I attempt to create a stored procedure to do the same as:
CREATE PROCEDURE TEST_PROC(IN IN_KEY VARCHAR(20), IN IN_TS TIMESTAMP)
MODIFIES SQL DATA
BEGIN ATOMIC
INSERT INTO TS_STORE(ID_COL, TS)
VALUES (IN_KEY, IN_TS);
END;
and attempt to call it as:
CALL TEST_PROC('key2', '2020-02-19 12:17:53');
Then I get an error: "incompatible data type in conversion".
This is a problem for me, since I am not allowed to change the signature of the the stored procedure to bypass the problem, since in my case HSQL is used as a mock for a production database (DB2) where the equivalent procedure works as expected.
It works if you call the procedure with a TIMESTAMP value, as opposed to the character string.
CALL TEST_PROC('key2', TIMESTAMP'2020-02-19 12:17:53');

cannot execute store procedure in phpmyadmin

Error in processing request: No routine with name `selectCategory` found
in database `xxx`.
This is my stored procedure
DELIMITER $$
CREATE DEFINER=`root`#`localhost` PROCEDURE `selectCategory`()
BEGIN
SELECT category_id, name AS display_name
FROM category
ORDER BY name;
END$$
DELIMITER ;
I am trying to run the stored procedure on the phpmyadmin site to check if the other problem I am having is due to php I wrote or the procedure itself, because of that error I cannot check and I do not know how to fix this error.
Is it possible that you are connecting to an instance which does not have the SP? check the db instance contains your SP.

Unable to retrieve multiple rows using cursor from database table using stored procedure DB2

I am trying to retrieve multiple rows from table using stored procedure and it doesn't work for me. My stored procedure is as follows,
CREATE OR REPLACE PROCEDURE E_Enquiry
(IN SourceQueue1 VARCHAR(30) ) LANGUAGE SQL
BEGIN
DECLARE C1 CURSOR FOR
select CreationTime
from ms.Exception_Message
where SourceQueue = SourceQueue1;
open c1;
END;
I am trying to call the stored procedure from Mule Anypoint Studio using the Database connector and have seen the result as null when I print the payload with a logger. If I try to modify the query as it returns a single row it works (without using cursor).
Please help to resolve this. Thanks.
What platform and version of DB2?
Try the adding
DYNAMIC RESULT SETS 1
WITH RETURN TO CLIENT
Like so:
CREATE OR REPLACE PROCEDURE E_Enquiry
(IN SourceQueue1 VARCHAR(30) )
LANGUAGE SQL
DYNAMIC RESULT SETS 1
BEGIN
DECLARE C1 CURSOR WITH RETURN TO CLIENT FOR
select CreationTime
from ms.Exception_Message
where SourceQueue = SourceQueue1;
open c1;
END;

DB2 - How do I create a Stored Procedure that ignores errors?

I am trying to create a simple stored procedure in DB2 that performs the following actions:
Drop table "DELETE_ME"
Create table "DELETE_ME"
Insert into table "DELETE_ME"
Basically, if the table DELETE_ME already exists, the stored procedure executes fine. If it does not exist, then the Stored Procedure fails with the following error:
Lookup Error - DB2 Database Error: ERROR [42704] [IBM][DB2/LINUXX8664] SQL0204N "SARTS02T.DELETE_ME" is an undefined name.
I completely understand this. However, I was hoping to set the procedure up to ignore this error (and all errors) that way the procedure can work as a deployment script as well. On the first deployment, it will ignore the drop table line and jump right to building the table.
I found a CREATE PROCEDURE option called CONTINUE AFTER FAILURE however I am receiving an error. Please see my code and error below. Thanks for your help!!!
CODE:
CREATE OR REPLACE PROCEDURE TEST_PROC LANGUAGE SQL CONTINUE AFTER FAILURE
BEGIN
DROP TABLE DELETE_ME;
CREATE TABLE DELETE_ME (
COLUMN_A DECIMAL(5)
);
INSERT INTO DELETE_ME (COLUMN_A) VALUES (69);
COMMIT;
END;
ERROR:
Lookup Error - DB2 Database Error: ERROR [42601] [IBM][DB2/LINUXX8664] SQL0104N An unexpected token "CONTINUE AFTER FAILURE" was found following "ST_PROC LANGUAGE SQL". Expected tokens may include: "<space>".
The BEGIN ... END section is called a compound statement which allows various declarations and other statements, including other compound statements, to be included inside it.
You'll want to declare a condition handler. You could do it something like this.
CREATE OR REPLACE PROCEDURE TEST_PROC
LANGUAGE SQL
COMMIT ON RETURN YES
BEGIN
DECLARE CONTINUE HANDLER FOR SQLSTATE '42704' -- or SQLEXCEPTION
BEGIN
-- insert any code here when DROP fails
END;
DROP TABLE DELETE_ME;
CREATE TABLE DELETE_ME
( COLUMN_A DECIMAL(5)
);
INSERT INTO DELETE_ME (COLUMN_A)
VALUES (69);
END;

Resources