Marius Vasile

Marius Vasile

  • 592
  • 1.9k
  • 145.5k

asp.net c# sql server select random data from table

Oct 1 2024 5:15 PM

I use a stored procedure to randomly select 40 rows from a table with

BEGIN
	INSERT INTO tblTestDetailSSM (IdIntrebare, IdUserTest) 
	SELECT TOP 40 ti.IdIntrebare AS IdIntrebare, @IdUserTest 
	FROM (SELECT TOP 100 * FROM tblIntrebare ORDER BY NEWID()) ti JOIN tblProcedura tp ON ti.IdProcedura = tp.IdProcedura WHERE tp.Specialitate = 'SSM' AND @CodTest IN (SELECT value FROM STRING_SPLIT(tp.CodTEST,','));
END

There are more than 200 items to pick from but the problem I have is that sometimes, it only picks 29 or less. What can I do to have exactly 40 every time?


Answers (1)