Click to See Complete Forum and Search --> : array parameter


shuvo
May 23rd, 2004, 09:23 AM
What I want to do is...suppose Its a table containing 50 questions and I have to select 30 questions out of it randomly. So in the select statement I have to use a where clause which will use a array parameter . that array will hold all the 30 serial numbers of the questions and depending on the serial numbers the questions will be selected from the table.If there is any Random fuction in Sql for random number generation and for using an array as the parameter of the where clause.Please let me know, I need help very quickly.

TheCPUWizard
May 23rd, 2004, 09:26 AM
I would tend to populate a temporary table with the 30 random numbers and return a join rather than trying to do it your way....

shuvo
May 23rd, 2004, 09:38 AM
No it is different....you have to randomly select rows from the Question bank table..the questions are number 1.2.3.4----so I have to retrieve 30 of them and form a dataset in .net Platform

shuvo
May 23rd, 2004, 09:48 AM
What I want to do is...suppose Its a table containing 50 questions and I have to select 30 questions out of it randomly. So in the select statement I have to use a where clause which will use a array parameter . that array will hold all the 30 serial numbers of the questions and depending on the serial numbers the questions will be selected from the table.If there is any Random fuction in Sql for random number generation and for using an array as the parameter of the where clause.Please let me know, I need help very quickly

TheCPUWizard
May 23rd, 2004, 09:52 AM
Please do not cross post. This thread is being reported to the moderator for merging....

hspc
May 23rd, 2004, 05:42 PM
as TheCPUWizard said :
create a temp table with random values then use a join or where ...in

declare @rand table(num tinyint not null)
declare @n tinyint
set @n=0
while @n<30
begin
Insert into @rand values(rand()*51)
set @n=@n+1
End
select * from questions where questionID in (select num from @rand)

Andy Tacker
May 24th, 2004, 02:22 AM
[moved & merged threads]

shuvo
May 24th, 2004, 08:22 AM
I needed advise from someone with vb.net experience,thats why I posted it in that section.Anyway I need to make this query in generating a DataSet object...will vb.net support this code in things like

dim objds as dataset()
dim conn as string
dim sqlstr as string

sqlstr= (all the sql code about temporary table that is given above)

dim objda as new oledbadapter(sqlstr,strconn)
objda.fill(objds)

hspc
May 24th, 2004, 10:46 AM
Originally posted by shuvo
...will vb.net support this code in things like

dim objds as dataset()
dim conn as string
dim sqlstr as string

sqlstr= (all the sql code about temporary table that is given above)

dim objda as new oledbadapter(sqlstr,strconn)
objda.fill(objds)
I think the answer is yes
why don't you just try it ?:)