Skip to main content
Inspiring
May 3, 2008
Question

Odd query problem

  • May 3, 2008
  • 4 replies
  • 236 views
Ok, here's the query I have:

<cfquery name="Results" datasource="SalleBoise">
select r_results_file
from clubtournaments, tournresults
where clubtournaments.TournID=tournresults.r_id
</cfquery>

The problem is that I'm getting results in the r_results_file for items
that don't match.

I'm first getting the ID's I need by:
<cfquery name="TournamentList" datasource="SalleBoise">
select * from clubtournaments
where
Tourndatetime > <cfqueryparam cfsqltype="cf_sql_date"
value="#DateAdd("d",-3,now())#">
and Tourndatetime < <cfqueryparam cfsqltype="cf_sql_date"
value="#DateAdd("m",3,Now())#">
</cfquery>

But I'm getting the ID of an event that has the date of 2008-04-05 09:00:00

And that ID is being used in the query at the top of this posting.......

Why would this be happening?
    This topic has been closed for replies.

    4 replies

    Inspiring
    May 4, 2008
    Your 2nd query does not use the information from the 1st one. I'm not sure why you need 2 queries anyway.

    If you want to ignore the time component of now(), use createdate to make 2 new variables and use those. Better yet, if your db has a current_date function, use it.
    Inspiring
    May 4, 2008
    Actually the 1st query is this one:

    <cfquery name="TournamentList" datasource="SalleBoise">
    select * from clubtournaments
    where
    Tourndatetime > <cfqueryparam cfsqltype="cf_sql_date"
    value="#DateAdd("d",-3,now())#">
    and Tourndatetime < <cfqueryparam cfsqltype="cf_sql_date"
    value="#DateAdd("m",3,Now())#">
    </cfquery>

    The 2nd is:

    <cfquery name="Results" datasource="SalleBoise">
    select r_results_file
    from clubtournaments, tournresults
    where clubtournaments.TournID=tournresults.r_id
    </cfquery>

    Do you have a suggestion on how to better use the date in the query, instead
    of now() ??

    "Dan Bracuk" <webforumsuser@macromedia.com> wrote in message
    news:fvkbua$jlq$1@forums.macromedia.com...
    > Your first query does not constrain on any date range. Also, when you use
    > now(), you get a time component of the date which may also present logic
    > problems for you.
    >

    Inspiring
    May 4, 2008
    Your first query does not constrain on any date range. Also, when you use now(), you get a time component of the date which may also present logic problems for you.
    Inspiring
    May 3, 2008
    Oh, and the values of r_id in the tournresults table is 1, and the value
    of TournID in the clubtournaments table is 2 ????

    Steve Grosz wrote:
    > Ok, here's the query I have:
    >
    > <cfquery name="Results" datasource="SalleBoise">
    > select r_results_file
    > from clubtournaments, tournresults
    > where clubtournaments.TournID=tournresults.r_id
    > </cfquery>
    >
    > The problem is that I'm getting results in the r_results_file for items
    > that don't match.
    >
    > I'm first getting the ID's I need by:
    > <cfquery name="TournamentList" datasource="SalleBoise">
    > select * from clubtournaments
    > where
    > Tourndatetime > <cfqueryparam cfsqltype="cf_sql_date"
    > value="#DateAdd("d",-3,now())#">
    > and Tourndatetime < <cfqueryparam cfsqltype="cf_sql_date"
    > value="#DateAdd("m",3,Now())#">
    > </cfquery>
    >
    > But I'm getting the ID of an event that has the date of 2008-04-05 09:00:00
    >
    > And that ID is being used in the query at the top of this posting.......
    >
    > Why would this be happening?