and more in a single search tool across platforms. Read the announcement here. |
02/14/2024 01:14 AM
Hello,
We have a usecase where we need to execute 2 queries in a dynamic attribute with conditional logic for loggedInUser attributes.
IF (loggedInUser's employeeType = 'Internal')
(select query)
ELSE
(select query)
Currently IF-ELSE is throwing 'Operation not allowed' on Data Analyzer. Could you please give access to use transaction based SQL statements in our Saviynt instance. Please suggest resolutions.
02/14/2024 01:56 AM - edited 02/14/2024 01:57 AM
Hi @tanvi_gaikwad ,
Try this :
SELECT (CASE WHEN a.employeetype = 'Internal'
THEN (SELECT userkey from users where userkey=a.userkey)
ELSE (
SELECT username from users where userkey=a.userkey
)
END) from (select userkey,employeetype from users where userkey=${requestor}) a
This is just a sample which you can use to your needs. I have tested it and it works in data analyzer, after replacing requestor to hard coded value for data analyzer.
Br - Amit
If helped, Please ACCEPT SOLUTION.
02/14/2024 02:05 AM
Hello Amit,
The select queries which we want to use return more than 1 values. CASE functionality does not allow more than 1 rows returned by a subquery. We are looking at something like this.
IF (loggedInUser's employeeType = 'Internal')
(select select attribute1 as ID from dataset_values where dataset_values.datasetname ='DATSETNAME')
ELSE
(select customproperty5 as id from users where userkey=$loggedInUser.id union select customproperty10 as id from users where userkey=$loggedInUser.id)
02/14/2024 10:02 PM
Please share full query
02/14/2024 10:59 PM
This is the query we are trying-
select CASE WHEN 'Internal User'!=(select employeeType from users where userkey=$loggedInUser.userkey) THEN (select customproperty5 as id from users where userkey=$loggedInUser.userkey UNION select customproperty10 as id from users where userkey=$loggedInUser.userkey) ELSE (select attribute1 as ID from dataset_values where dataset_values.datasetname ='HONDA_CENTER_MAPPING') END AS ID
The subqueries return more than 1 row. Therefore we were trying to handle it using IF-ELSE. But IF-ELSE operation is not allowed on Data Analyzer
02/14/2024 11:04 PM
SELECT
CASE
WHEN 'Internal User' != (SELECT employeeType FROM users WHERE userkey = $loggedInUser.userkey)
THEN (SELECT customproperty5 AS id FROM users WHERE userkey = $loggedInUser.userkey
UNION
SELECT customproperty10 AS id FROM users WHERE userkey = $loggedInUser.userkey)
ELSE (SELECT attribute1 AS ID FROM dataset_values WHERE dataset_values.datasetname = 'HONDA_CENTER_MAPPING')
END AS ID;
update actual users userkey
02/14/2024 11:07 PM
SELECT
CASE
WHEN 'Internal User' != (SELECT employeeType FROM users WHERE userkey = 9)
THEN (SELECT customproperty5 AS id FROM users WHERE userkey = 9
UNION
SELECT customproperty10 AS id FROM users WHERE userkey = 9)
ELSE (SELECT attribute1 AS ID FROM dataset_values WHERE dataset_values.datasetname = 'HONDA_CENTER_MAPPING')
END AS ID;
02/14/2024 11:14 PM
Query works for me
02/14/2024 11:49 PM
How many entries does your dataset have?