Dear Friends
i want to create dynamic id on base of datacolumn .So tell me Operation should do in database or C# code .which will be best .
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Khargesh RajputPosted Apr 24, 2015, 2:44 AM
Random r = new Random();
// Always 5, 6, 7, 8 or 9.
Console.WriteLine(r.Next(5, 10));
Console.WriteLine(r.Next(5, 10));
Console.WriteLine(r.Next(5, 10));
for sql
DECLARE @Upper INT; DECLARE @Lower INT;
SET @Lower = 1 -- The lowest random number
SET @Upper = 49 -- The highest random number
SELECT @Lower + CONVERT(INT, (@Upper-@Lower+1)*RAND())
To get random number
without repetition I think this will do the job
;with CTE as ( SELECT randomNumber, COUNT(1) countOfRandomNumber FROM ( SELECT ABS(CAST(NEWID() AS binary(6)) %49) + 1 randomNumber FROM sysobjects) sample GROUP BY randomNumber ) SELECT TOP 5 randomNumber FROM CTE ORDER BY newid()