0

I have searched through posts and the shortest and easiest I could find was

CONVERT(varchar(255), NEWID())

However, this as expected creates an alphanumeric string . Translate is available in Oracle but I am working on SQL Server and nothing of the kind is available in here. I however wanted a string that has characters only.

Can I please get some directions on this? Any help is much appreciated.

3
  • 1
    What sort of random output are you expecting? How much entropy do you require? Commented Feb 19, 2015 at 16:01
  • 1
    If pseudo randomness is all you need, have a look here: stackoverflow.com/questions/2152204/… Commented Feb 19, 2015 at 16:02
  • @YannickMeeus: That answered my question. Thank you. Commented Feb 19, 2015 at 16:13

1 Answer 1

1

Just an "ugly" evolution of your code, but it works

DECLARE @NewId nvarchar(45)
set @NewId = newid()

SELECT replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(@NewId, 1, 'A'), 2, 'B'), 3, 'C'), 4, 'D'), 5, 'E'), 6, 'F'), 7, 'G'), 8, 'H'), 9, 'I'), 0, 'L'), '-', 'M')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.