SQL

Generate Unique Random Numbers In Sql Stored Procedure

This procedure generates random unique numbers between two numbers. It gets 3 parameters. The first parameter is number you want to list, the second parameter is the start value and the last parameter is the end value. In this proceure we used table variable. With table variable we saved numbers. We checked if the number exists in the tablei if not exists then the number is added to the table variable.

After you run the code above than you run the code below.

Result:Ā Lists 5 numbers between 20 and 30

Result:Lists 6 numbers between 0 and 49

 

Result:Lists 10 numbers between 50 and 100

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.