Generating random strings with T-SQL

前端 未结 27 1855
青春惊慌失措
青春惊慌失措 2020-11-29 18:10

If you wanted to generate a pseudorandom alphanumeric string using T-SQL, how would you do it? How would you exclude characters like dollar signs, dashes, and slashes from

27条回答
  •  一整个雨季
    2020-11-29 18:39

    Based on various helpful responses in this article I landed with a combination of a couple options I liked.

    DECLARE @UserId BIGINT = 12345 -- a uniqueId in my system
    SELECT LOWER(REPLACE(NEWID(),'-','')) + CONVERT(VARCHAR, @UserId)
    

提交回复
热议问题