Random number generation in sql
I want employees id to be fetched randomly by using the blow query
select Top 2 SessionId from Flash_Temp2
order by NEWID()
but instead of top 2, i want to pass it in a variable as its depend on the situation for ex:
declare @id int
set @id=3
select Top @id SessionId from Flash_Temp2
order by NEWID()
it givs following error:
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '@id'.