Question

I am retreiving information from a BES (Blackberry Enterprise Server). I need to change the Display Name field from the BES to a name.name format.

The Display name comes across as First Last and possible First Last-EXT for example. I need to drop the dash after any last name with it, and also add a . between first and last.

I have tried using REPLACE to add the . And I have tried CASE to remove the - and everthing after it. But how can I combine into one statement to do both?

,CASE WHEN CHARINDEX('-',[DisplayName])>0 THEN LEFT([DisplayName], CHARINDEX('-',[DisplayName])-1) ELSE [DisplayName] END

,REPLACE([DisplayName], ' ','.') AS 'Display Name'

edit : added code block

Was it helpful?

Solution

Try below code.

you have done all the work.

in your case statement you return the DisplayName that you want (removing '-' from lastname and every character following '-') so use that output and apply replace to replace your blank space to '.'

 CASE WHEN CHARINDEX('-',[DisplayName])>0 
      THEN REPLACE(LEFT([DisplayName], CHARINDEX('-',[DisplayName])-1), ' ','.') 
      ELSE REPLACE([DisplayName], ' ','.') 
 END
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top