On Fri, Sep 17, 2010 at 10:55 AM, Peter Smith <[email protected]> wrote: > > > On Thu, Sep 16, 2010 at 9:53 PM, Nawal <[email protected]> wrote: >> >> hi !!! all >> plz give me ans ..... >> >> Question.--> select 10 number randomly in 100 no.'s database ???? > > Copy the table to #newtable > Delete rows randomly tillĀ SELECT COUNT(*) FROM #NEWTABLE is equal to 10 > SELECT * FROM #NEWTABLE > > There you go. :) > -------------------------------
If all you have to do is select 10 random Numbers why operate against a table at all? Now if you had to pick 10 random customers that would be a lot more fun! DECLARE @RandomNumber float DECLARE @RandomInteger int DECLARE @MaxValue int DECLARE @MinValue int Declare @strNum Char(4) SET @MaxValue = 99 SET @MinValue = 1 SELECT @RandomNumber = RAND() SELECT @RandomInteger = ((@MaxValue + 1) - @MinValue) * @RandomNumber + @MinValue SELECT @RandomNumber as RandomNumber, @RandomInteger as RandomInteger select '%' + cast(@RandomInteger as char(2)) +'%' as @strNum Select top 10 CustomerName from Customers where customerZip like @strNum order by customerAddress -- Stephen Russell Sr. Production Systems Programmer CIMSgts 901.246-0159 cell
