RE: COMPLEX SQL RANDOM: SOLVED

2011-08-04 Thread Robert Harrison
#x27;t be either/or.  It must be &. Plug in to our blog: A&W Unplugged http://www.austin-williams.com/unplugged -Original Message- From: Maureen [mailto:mamamaur...@gmail.com] Sent: Thursday, August 04, 2011 1:38 PM To: cf-talk Subject: Re: COMPLEX SQL RANDOM: SOLVED Is there

Re: COMPLEX SQL RANDOM: SOLVED

2011-08-04 Thread Maureen
Is there a reason you are selecting portal_polls.answer2 and portal_polls.answer4 twice, or is that a typo? On Thu, Aug 4, 2011 at 6:13 AM, Robert Harrison wrote: > > Thanks for all of your answers. I tried a few of the suggestions but they > weren't quite right. > > Bill Franklin's answer, whi

RE: COMPLEX SQL RANDOM

2011-08-04 Thread Bill Franklin
: Jochem van Dieten [mailto:joch...@gmail.com] Sent: Wednesday, August 03, 2011 3:08 PM To: cf-talk Subject: Re: COMPLEX SQL RANDOM On Wed, Aug 3, 2011 at 9:36 PM, Bill Franklin wrote: > Why not try something like this...(not sure which database you are using) > > SELECT TOP 1

RE: COMPLEX SQL RANDOM: SOLVED

2011-08-04 Thread Robert Harrison
Thanks for all of your answers. I tried a few of the suggestions but they weren't quite right. Bill Franklin's answer, while not complete, made me rethink what I was doing from a different point of view. My error was that I was chaining all of the record together as though I was trying to se

Re: COMPLEX SQL RANDOM

2011-08-03 Thread Leigh
> Not that I am aware off. But then again, I didn't even know > that > uniqueidentifiers had a comparator nowadays and could be > sorted :) Yeah, it is hard to keep up with all the changes. Anyway, I may have a around later. If I actually manage to find a reference, I will post back ;) -Lei

Re: COMPLEX SQL RANDOM

2011-08-03 Thread Jochem van Dieten
On Wed, Aug 3, 2011 at 10:13 PM, Leigh wrote: > Offhand do you know if there are any issues using NEWID() within CTE's? I > have a vague recollection of issues with that function. Either when used > within CTE's or possible derived tables. Not sure. Not that I am aware off. But then again, I di

Re: COMPLEX SQL RANDOM

2011-08-03 Thread Leigh
Offhand do you know if there are any issues using NEWID() within CTE's? I have a vague recollection of issues with that function. Either when used within CTE's or possible derived tables. Not sure. -Leigh ~| Order the Adobe C

Re: COMPLEX SQL RANDOM

2011-08-03 Thread Jochem van Dieten
On Wed, Aug 3, 2011 at 9:36 PM, Bill Franklin wrote: > Why not try something like this...(not sure which database you are using) > > SELECT TOP 1 * > FROM > ( >        SELECT DISTINCT portal_polls.poll_id, portal_polls.question, > portal_polls.answer1, portal_polls.answer2, portal_polls.answer2,

Re: COMPLEX SQL RANDOM

2011-08-03 Thread Leigh
> because every row in your > resulting recordset now has a field called fieldC with the > value of your previously generated ID That is because a variable is used rather of calling the function directly within the SELECT list. The latter (usually) forces the function to be evaluated once per r

Re: COMPLEX SQL RANDOM

2011-08-03 Thread Jochem van Dieten
On Wed, Aug 3, 2011 at 8:43 PM, Robert Harrison wrote: > Normally I would use TOP 1 and ORDER BY NEWID() to do this.  But it doesn't > like that with the DISTINCT clase. I'm using DISTINCT because the same poll > could come up several times if it's allowed in multiple groups and that use > is i

RE: COMPLEX SQL RANDOM

2011-08-03 Thread Bill Franklin
id and portal_students_x_polls_completed.student_user_id=#session.userid#); ) -Original Message- From: Steve Milburn [mailto:scmilb...@gmail.com] Sent: Wednesday, August 03, 2011 2:33 PM To: cf-talk Subject: Re: COMPLEX SQL RANDOM The error message you are getting is because the value of your order by clause, newID

Re: COMPLEX SQL RANDOM

2011-08-03 Thread Steve Milburn
The error message you are getting is because the value of your order by clause, newID(), is not a part of your list of values you are selecting. You could, of course, include it in your list of values by first setting it to a variable, like so: declare @orderClause as uniqueidentifier; set @order

RE: COMPLEX SQL RANDOM

2011-08-03 Thread Leigh
> But when I do that it tells me: ORDER BY items must appear > in the select list if SELECT DISTINCT is specified. I cannot speak for the query itself, but using a derived table comes to mind as a possibility. ~| Order the Adob

RE: COMPLEX SQL RANDOM

2011-08-03 Thread Robert Harrison
> Since the query you have gives you the list of polls that you want, what > about dumping the results of that query into a temp table, and doing a random > select on the temp table with SELECT TOP 1 and ORDER BY NEWID() ? I have considered that, but this should be possible in one straight up S

Re: COMPLEX SQL RANDOM

2011-08-03 Thread Steve Milburn
Since the query you have gives you the list of polls that you want, what about dumping the results of that query into a temp table, and doing a random select on the temp table with SELECT TOP 1 and ORDER BY NEWID() ? Steve On Wed, Aug 3, 2011 at 2:43 PM, Robert Harrison wrote: > > I have this

RE: COMPLEX SQL RANDOM

2011-08-03 Thread Robert Harrison
What I'm trying to do should look like this: SELECT DISTINCT TOP 1 portal_polls.poll_id, portal_polls.question, portal_polls.answer1, portal_polls.answer2, portal_polls.answer2, portal_polls.answer4, portal_polls.answer4, portal_polls.number_answers FROM portal_polls,