Home Forums SQL Server 7,2000 T-SQL How using SQL to generate random string? RE: How using SQL to generate random string?

  • Sharul Nizam (11/21/2009)


    Garadin (11/21/2009)


    Before we give you crazy solutions to accomplish this, could you share the reason for it and what you hope to accomplish?

    1. Me just want to see, Stored Procedure can comply this or not

    2. If Stored Procedure can't doing this, me have no choice. As a result, the coding will be at front-end

    There are very few limitations on what you *can* do in T-SQL. There are considerably more on things you *should* do. Could you set up a loop with a string generator to check for whether or not it exists in the table and if so, generate a new one until it does not? Yes. Should you? It depends... but I certainly can't come up with a valid reason to do so. Which is why I want to hear what your actual requirement is... there may be a much better way to accomplish your actual goal. All the different limitations you put on it combine to make this considerably more convoluted.

    For example:

    Does it really need to be random?

    Does it really need to be 6 characters or can it be longer?

    Does it really need to use all the characters of the alphabet and 0-9?

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]