Possible Duplicate:
Generating random strings with T-SQL
I need to generate a random string with alpha and numeric characters inside a trigger.
The string must have a length of 15 and uppercase.
Someone have an idea?
Possible Duplicate:
Generating random strings with T-SQL
I need to generate a random string with alpha and numeric characters inside a trigger.
The string must have a length of 15 and uppercase.
Someone have an idea?
This is far from an optimal solution, but it will work as specified:
select char(rand()*26+65)+char(rand()*26+65)+char(rand()*26+65)
+char(rand()*26+65)+char(rand()*26+65)+char(rand()*26+65)
+char(rand()*26+65)+char(rand()*26+65)+char(rand()*26+65)
+char(rand()*26+65)+char(rand()*26+65)+char(rand()*26+65)
+char(rand()*26+65)+char(rand()*26+65)+char(rand()*26+65)
Example output:
WCZOVRCIRELAJUT
generate a GUID and take just the first 15 characters?
Generate a bunch of random numbers and translate to their ASCII values?
cast(cast(NEWID() as varbinary(max)) as varchar(max)) is what you are suggesting in this answer. One potential issue is that there will be random special characters like ASCII 0 (null).