User defined SQL function in Query box fails.

Post Reply
hiits100rav
Posts: 8
Joined: Fri Feb 26, 2016 8:22 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: Excel 2013

User defined SQL function in Query box fails.

Post by hiits100rav »

Hi,

I have created a function in MySQL which I want to call in my query box in data source tab. However it seems to be not working and fails. The same query works when run on sql prompt. I am an newbie to TI processes. Can anyone share their experience on this?

As a simple example:
SELECT 'a.txt' as fileid, getFileStatus('a.txt') file_status;

Many Thanks,
Saurabh
Wim Gielis
MVP
Posts: 3230
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.1.5
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: User defined SQL function in Query box fails.

Post by Wim Gielis »

Not sure if a stored procedure can be set up and called from TI ?
Best regards,

Wim Gielis

IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
BrianL
MVP
Posts: 264
Joined: Mon Nov 03, 2014 8:23 pm
OLAP Product: TM1
Version: 9.5.2 10.1 10.2 PA2
Excel Version: 2016

Re: User defined SQL function in Query box fails.

Post by BrianL »

hiits100rav wrote:However it seems to be not working and fails.
How is it failing? Is there an error message?
User avatar
paulsimon
MVP
Posts: 808
Joined: Sat Sep 03, 2011 11:10 pm
OLAP Product: TM1
Version: PA 2.0.5
Excel Version: 2016
Contact:

Re: User defined SQL function in Query box fails.

Post by paulsimon »

Hi

I can confirm that stored procedures as data sources work fine with SQL Server. User Defined Functions are a little different in that in SQL they can't be a data source in their own right. However, used in the Select clause they work on SQL Server. I have never used MySQL so I can't comment on that but I don't see any reason why it should be any different.

Please post the actual SQL The example that you posted doesn't have From clause, which is needed, and you will probably find that you don't need the closing semi colon in an ODBC query

Regards

Paul Simon
hiits100rav
Posts: 8
Joined: Fri Feb 26, 2016 8:22 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: Excel 2013

Re: User defined SQL function in Query box fails.

Post by hiits100rav »

Hi Guys,

Apologies for the delay in response. The error that I am receiving is "SQL statement failed" while performing preview.

Paul SImon - The query is actual, that said, mysql doesn't force to use 'from' clause. ("Select 1" works in mysql).

Interesting that SQL server stored procedure does work for TI and not working for MySQL (atleast for me). Here is the function I defined in mysql and test query:
I am able to define the function in run the query correctly in SQL workbench.
Query:
select getDraftStatus('abc.csv')

Function:
DELIMITER $$
DROP FUNCTION getDraftStatus $$
CREATE FUNCTION getDraftStatus (p_file_name Varchar(50))
RETURNS int(4)
DETERMINISTIC
BEGIN
DECLARE file_status int(4);

SET file_status = -1;

SELECT status into file_status
FROM table1
WHERE file_id = p_file_name
ORDER BY created DESC
LIMIT 1;

RETURN (file_status);

END; $$

DELIMITER ;
Post Reply