-1

I have a table that has a column called Name.

It has data:

John
Jack
Josh
Bob
...

I want to run a query to re-arrange the letters for the names.

UPDATE [table]
SET [name] = ?

Result:

hnoJ
ckJa
shoJ
boB

Is it possible to do this?

Robert
  • 25,425
  • 8
  • 67
  • 81
JJ.
  • 9,580
  • 37
  • 116
  • 189
  • 1
    What rules are used for this? – Oded Sep 10 '12 at 19:52
  • possible duplicate of [Shuffle a string with mysql/sql](http://stackoverflow.com/questions/11860023/shuffle-a-string-with-mysql-sql) – Sean Bright Sep 10 '12 at 19:53
  • there are no rules. I just want to re-arrange the letters so that I can't tell which name was there in the first place (even though you might be able to guess). im basically taking production data and moving it to development but certain fields need to be changed because it might be confidential information – JJ. Sep 10 '12 at 19:53
  • 1
    I think you may need to employ another programming language for this kind of endeavour. Use a pseudorandom generator to create random numbers for each of the letters, then sort the letters according to those letters. Then run that Update query with the result. – ATaylor Sep 10 '12 at 19:54
  • What if the name is a single character (like Prince). How will your routine obfuscate it then? – D'Arcy Rittich Sep 10 '12 at 19:56

1 Answers1

3

This is not very pretty but it will mix up the letters:

select right(name, 2) 
  + reverse(left(name, len(name) - 2))
from names

see SQL Fiddle with Demo

Taryn
  • 242,637
  • 56
  • 362
  • 405