Saviynt unveils its cutting-edge Intelligence Suite products to revolutionize Identity Security!
Click HERE to see how Saviynt Intelligence is transforming the industry.
Saviynt Copilot Icon

System Generation Rule remove spaces

cdavis2
Regular Contributor III
Regular Contributor III

I have the following rule and I have a use case where there are spaces in the last name and first name I need to remove those spaces. Can someone assist with my current rule with removing those spaces?

case when length(trim(users.lastname)) between 2 and 50 then
concat
(
substring(users.firstname,1,1), users.lastname
,
case
when (select count(*) from users X where substring(X.firstname,1,1) = substring(users.firstname,1,1) and X.lastname = users.lastname) in (0 , 1) then ''
else
(select count(*) from users X where substring(X.firstname,1,1) = substring(users.firstname,1,1) and X.lastname = users.lastname)
end
)
else
concat(users.firstname, users.lastname,
case
when (select count(*) from users X where X.firstname = users.firstname and X.lastname = users.lastname) in (0 , 1) then ''
else
(select count(*) from users X where X.firstname = users.firstname and X.lastname = users.lastname)
end
)
end

1 REPLY 1

rushikeshvartak
All-Star
All-Star
CASE 
    WHEN LENGTH(TRIM(users.lastname)) BETWEEN 2 AND 50 THEN
        CONCAT
        (
            SUBSTRING(REPLACE(users.firstname, ' ', ''), 1, 1), 
            REPLACE(users.lastname, ' ', ''),
            CASE
                WHEN (SELECT COUNT(*) FROM users X 
                      WHERE SUBSTRING(REPLACE(X.firstname, ' ', ''), 1, 1) = SUBSTRING(REPLACE(users.firstname, ' ', ''), 1, 1) 
                        AND REPLACE(X.lastname, ' ', '') = REPLACE(users.lastname, ' ', '')) IN (0, 1) THEN ''
                ELSE 
                    (SELECT COUNT(*) FROM users X 
                     WHERE SUBSTRING(REPLACE(X.firstname, ' ', ''), 1, 1) = SUBSTRING(REPLACE(users.firstname, ' ', ''), 1, 1) 
                       AND REPLACE(X.lastname, ' ', '') = REPLACE(users.lastname, ' ', ''))
            END
        )
    ELSE
        CONCAT(REPLACE(users.firstname, ' ', ''), REPLACE(users.lastname, ' ', ''),
            CASE
                WHEN (SELECT COUNT(*) FROM users X 
                      WHERE REPLACE(X.firstname, ' ', '') = REPLACE(users.firstname, ' ', '') 
                        AND REPLACE(X.lastname, ' ', '') = REPLACE(users.lastname, ' ', '')) IN (0, 1) THEN ''
                ELSE 
                    (SELECT COUNT(*) FROM users X 
                     WHERE REPLACE(X.firstname, ' ', '') = REPLACE(users.firstname, ' ', '') 
                       AND REPLACE(X.lastname, ' ', '') = REPLACE(users.lastname, ' ', ''))
            END
        )
END

Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.