• Ouch.

    I would modify the CLR Udf to returns a data set of '@amount' Codes and store those to a temp table.

    Then delete duplicates with the codes table and re-execute the UDF returning the rowcount from the delete.

    Repeat until there are no duplicate rows.

    This will minimize the amount of round trips to the udf , plus the SQL logic is much more set based.

    Ive never used the RNGCryptoServiceProvider class but you may only have to have one instance of if it if GetBytes returns a different value at each call.

    As another thought though does all this function do return a string of variable(edit: random) characters from '34679CDFGHJKLNPRTVXY' ?

    If so a pure TSQL solution should be pretty simple

    Post back if this isn't clear



    Clear Sky SQL
    My Blog[/url]