The Student Room Group

Need help with an SQL query

Hi there, I have the following SQL query

"SELECT TOP '" + q + "' questionID FROM Question WHERE courseID = '" + c + "' ORDER BY Rnd(questionID)"

where q and c are variables passed into the method containing this query as arguments

this is returning null, when I know that q and c definately have appropiaote values in them, why is this??

Any help somebody can give me would be great, many thanks.
Reply 1
This query will return some tuple if q > 0 and c is a existing courseID.
The "order by" doesn't influence
Your Question table is big? You can show it?
Post the table and parameters q and c that you tested and returned null.
Reply 2
Original post by felipe87
This query will return some tuple if q > 0 and c is a existing courseID.
The "order by" doesn't influence
Your Question table is big? You can show it?
Post the table and parameters q and c that you tested and returned null.


Thank you for your reply.

Yes, I have prepared for it to return more than one row, yes c is an exisitng courseID.
ok.
No there aren't many questions there at the moment, but it will have.
QuestionTable.png

I get a nullReference in my c# code from the List<int> that the method containing the query returns to
Reply 3
I created a table like you in MS Access and following SQL:

SELECT top 1 Question.[questionID]
FROM Question
where Question.[courseID] = 'AWD01'
order by Rnd(Question.[questionID]);

And works!
You are using quote to courseID column?

Quick Reply

Latest

Trending

Trending