395
Views
4
Comments
Correct Use of the SQL Functions String_Split and Substring function
Question

I have the SQL code below ( where the @Province input parameter is in this form): 

"[""Central District","Central Region","Delaware","Drenthe","Eastern Cape","Free State","Gauteng","Hardap Region","Haryana","Karas Region","KwaZulu Natal","KwaZulu-Natal","Limpopo","Lorestan Province","Mpumalanga","North West","Northern Cape","Pennsylvania","Qarku i Tiranës","State of Rio de Janeiro","Toscana","Wes-Kaap","Western Cape""]" 

WITH ProvinceList as (
    SELECT CAST (value AS nvarchar) name FROM STRING_SPLIT(SUBSTRING(@Provinces, 3, LEN(@Provinces)-3), ',')
)

SELECT {Site}.*
FROM {Site}

WHERE ({Site}.[Province] IN -- Get all Province names in list sent
        (SELECT name 
        FROM ProvinceList))
            
ORDER BY {Site}.[Name] ASC 

However when I test my SQL I get no rows returned. Please assist.

2024-03-14 14-46-22
Nelson Inácio

Hi,

Is your application is muli tenant? If yes you might be using the wrong tenant

UserImage.jpg
boipelo kedikilwe

Nelson Inácio wrote:

Hi,

Is your application is muli tenant? If yes you might be using the wrong tenant

 Could you kindly offer more clarity on what you mean and what my possible approach to my issue should be. I am still at a very novice level of Outsystems. 

Regards

 

2018-06-05 16-54-03
Maria da Graça Peixoto

Hi! 

Could you kindly test an Advanced SQL just with the expression below?

SELECT     value  FROM     STRING_SPLIT('red,green,,blue', ','); 


This is just the example in the SQL Server tutorial but it seems the function do not work in OutSystems

Hope this help you

Graça

2020-07-29 19-08-40
Sanjay Kumar Sahu

Hello Boipelo,


You don't need to use SQL function for Substring, there is an inbuilt function in OS, see below:

I would like to suggest you kindly go through this link for your better understanding of these 2 function :

https://www.outsystems.com/forums/discussion/50322/how-to-use-string-split/ 


Regards,

Sanjay

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.