Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
wdchristensen
Specialist
Specialist

SQL Server User Defined Function (UDF) generates error in load script

When I attempt to use SQL Server User Defined Function in my SQL code in load script (qlik sense) it generated a cryptic error. I have ensured that the connection account has access to the udf and everything runs perfectly under the same account in SSMS. I have tried other udfs which generate similar errors. For the sake of this example, I used the validate email function below:


Create FUNCTION [dbo].[udf_ValidateEmail] (@email varChar(255))


RETURNS bit

AS

begin

return

(

select

Case

When @Email is null then 0                 --NULL Email is invalid

When charindex(' ', @email) <> 0 or --Check for invalid character

charindex('/', @email) <> 0 or --Check for invalid character

charindex(':', @email) <> 0 or --Check for invalid character

charindex(';', @email) <> 0 then 0 --Check for invalid character

When len(@Email)-1 <= charindex('.', @Email) then 0--check for '%._' at end of string

When @Email like '%@%@%'or

@Email Not Like '%@%.%'  then 0--Check for duplicate @ or invalid format

Else 1

END

)

end


UDF_Mystery.png

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I tested in Nov2017 patch 1 desktop and it worked without error.

Interestingly, when I code it up in a Query Window in SQL Management studio,  I get a syntax underline with the exact error message you posted.  However it executes fine.

-Rob

View solution in original post

11 Replies
marcus_sommer

Your select-statement isn't complete - it is missing the marked part:

Select * from "SomeTestDB".....

Further I doubt that you could call the UDF in this way - normally functions are called with:

function(FIELD) as FieldAdjusted

- Marcus

snehamahaveer
Creator
Creator

Hello,

The SQL select generally has the path at the end.

So something like the below might help

SQL Select

*

From UDf.ValidateEmail;

or

Select

Field1,

Field2 as TestUDF

From

[testdb].[dbo].[UDF.ValidateEmail];

wdchristensen
Specialist
Specialist
Author

UDF_SQLexample.png

wdchristensen
Specialist
Specialist
Author

Thanks for the responses!


In an attempt to keep the example simple, I neglected to include a “from” clause as is unnecessary to illustrate my point. The error is the same if I were to call the udf as follows:


Select *, [testdb].[dbo].[ValidateEmail] ('TestEmail@gmail.com')

from [testdb].[dbo].[EmployeeTbl];

marcus_sommer

Ok. It seems to be a valid sql-statement within your database but your used database-driver must support it and return some kind of table to Qlik - I have some doubts that it will return a table else that it is some kind of special feature within your db.

- Marcus

marcus_sommer

I would rather try an approach like:

Select *, UDF.ValidateEmail('TestEmail@gmail.com') as Email

from [testdb].[dbo].[EmployeeTbl];

- Marcus

wdchristensen
Specialist
Specialist
Author

With the revised query syntax I get the same error.

marcus_sommer

I would check if a select * from on the table worked. If yes and then afterwards the function-call of your UDF failed meant that either the call-syntax is wrong or the driver didn't support it - maybe there are alternate drivers available.

- Marcus

wdchristensen
Specialist
Specialist
Author

The sql works in the load script until I add the UDF with a parameter.

I use the Microsoft OLE DB Provider for SQL Server driver with other tools using udfs with no issues so it is looking like a Qlik bug to me. Unfortunately I am on Qlik Sense 3.2 and I am pretty sure this bug has been fixed 'November 2017' so all I really need to do is upgrade, right? #psychic

connectionSQLServer.png

I appreciate you taking the time to reply to my issue. Thanks