2
Answers

Trying to Randomly select 3 records from Data base..

Ben meade

Ben meade

13y
1.8k
1
  Hey There,
     I am relativley new to C# and VS2010 and I been assigned a task of reading the DB and randomly selecting 3 records that meet certain criteria to be displayed on the user screen, so they can choose which record they want to use.  I am using C# and VS2010 and it will be a Windows application.  I certainly would appreciate any help. I have looked on Google and the examle I have found there only talk about numbers....


Thanks,
Ben
Answers (2)
0
Marcel Hertel

Marcel Hertel

NA 54 0 14y
hi,

assume that you have the columns emp_id and emp_name in your emp-table you can use the following procedure:

create procedure sp_Sortdata
(
    @Orderbyclause varchar(50)
)
as
select
    *
from
    emp e
order by   
    case when @Orderbyclause = 'emp_id' then e.emp_id end asc
    ,case when @Orderbyclause = 'emp_name' then e.emp_name end asc
   
if you execute exec sp_Sortdata 'emp_id' the procedure returns the emp-table ordered by emp_id

i hope this helps

Marcel Hertel