PARTNERS - Please join us for our upcoming webinar:
Leveraging Intelligent Recommendations for Operational Transformation.
AMS Partners click HERE | EMEA/APJ Partners click HERE

SystemUserName generation using SQL query

priyag
New Contributor
New Contributor

Hello
I want to generate the StemUserName according to the following conditions.
all lowercases and limited to 20 characters if necessary truncate last name 
only take firstname first letter

<Lower Case FirstName>.<Lower Case LastName><xxx> - where xxx is only used to avoid duplication. So if we have two users named Smith Jorden, the first would be

s.jorden and the second would be s.jorden001.

1 REPLY 1

rushikeshvartak
All-Star
All-Star

LEFT(CASE WHEN users.firstname IS NOT NULL AND users.firstname!= '' THEN LOWER(SUBSTRING(users.firstname, 1, 1)) || '.' || LOWER(SUBSTRING(users.lastname, 1, 16)) ELSE LOWER(SUBSTRING(users.firstname, 1, 1)) || '.' || LOWER(SUBSTRING(users.lastname, 1, 16)) END || LPAD(ROW_NUMBER() OVER (PARTITION BY CASE WHEN users.firstnameIS NOT NULL AND users.firstname!= '' THEN LOWER(SUBSTRING(users.firstname, 1, 1)) || '.' || LOWER(SUBSTRING(users.lastname, 1, 16)) ELSE LOWER(SUBSTRING(users.firstname, 1, 1)) || '.' || LOWER(SUBSTRING(users.lastname, 1, 16)) END ORDER BY users.id)::text, 3, '0'), 20)


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