1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
CREATE VIEW [dbo].[v_newid] AS SELECT NEWID() AS f_new_id CREATE FUNCTION fx_random_string ( @Length INT ) RETURNS VARCHAR(20) AS BEGIN DECLARE @s VARCHAR(20); SET @s = ( SELECT f_letter AS [text()] FROM ( SELECT TOP (@Length) f_letter FROM ( VALUES ('a'), ('b'), ('c'), ('d'), ('e'), ('f'), ('g'), ('h'), ('i'), ('j'), ('k'), ('l'), ('m'), ('n'), ('o'), ('p'), ('q'), ('r'), ('s'), ('t'), ('u'), ('v'), ('w'), ('x'), ('y'), ('z'), ('0'), ('1'), ('2'), ('3'), ('4'), ('5'), ('6'), ('7'), ('8'), ('9') ) AS t (f_letter) ORDER BY ABS(CHECKSUM((SELECT f_new_id FROM v_newid))) --random order ) AS t FOR XML PATH('') ); RETURN @s; END |
Friday, May 20, 2016
MSSQL: Random String Generator
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment