SQL Query not return date if we use <> operators

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default SQL Query not return date if we use <> operators

    Hi,

    I am in a way at this moment where I have to find records from tables where
    date are the primary field to be validated. In another word, I tried to
    recuperate records by using StartingDate >= '#myDate#' but it seems that the
    MS-SQL Server never return any records. But if I tried from the MS-SQL
    Enterprise Manager (Query), it returns records. So it is between ColdFusion MX
    (I use the Version 7 in Developer edition and Standard Edition) and ODBC. But I
    have to admit that I am completely confused by this issue.

    I also tried to create a SQL Procedure and use the CFPROCEDURE but without any
    success.

    Thank you for any help! And if you need a little bit more explication, I will
    be glad to supply more.

    <cffunction name="fConvertToCADHebdo">
    <cfargument name="currencyid" required="true">
    <cfargument name="amount" required="true">
    <cfargument name="dtExpense" required="true">
    <cftrace text="CurrencyID = #currencyid#">
    <cftrace text="amount = #amount#">
    <cftrace text="dtExpense = #dtExpense#">
    <cfset vReturn = "">
    <cfquery name="qGetCurrencyRates" datasource="#Application.DSN#">
    SELECT *
    FROM currencyConversion
    WHERE StartingDate >= <cfqueryparam value="#dtExpense#"
    cfsqltype="cf_sql_date">
    ORDER BY StartingDate ASC
    </cfquery>
    <cfdump var="#qGetCurrencyRates#" label="qGetCurrencyRates">
    <cfif qGetcurrencyRates.RecordCount gt 0>
    <cftrace text="qGetCurrenctRates.RecordCount is gt 0">
    <cfquery name="qGetRates" datasource="#Application.DSN#">
    SELECT *
    FROM currencyConversion
    WHERE id = #qGetCujrrencyRates.id[1]#
    </cfquery>
    <cfif qGetRates.RecordCount gt 0>
    <cftrace text="qGetRates.RecordCount gt 0">
    <cfset vReturn = qGetRates.id>
    </cfif>
    </cfif>

    <cfreturn vReturn>
    </cffunction>

    <cfset vExpenses = 200.99>
    <cfset vExpenseCurrencyID = 2>
    <cfset vExpenseDate = '2/4/2005 00:00:00'>


    <cfset vTemp = fConvertToCADHebdo(vExpenseCurrencyID, vExpenses, vExpenseDate)>
    <cfoutput>#vTemp#</cfoutput>

    francois-yanick Guest

  2. Similar Questions and Discussions

    1. Date.toLocaleDateString() does not return Japaneseformat under ja_JP locale
      Hi, My understanding is that Flex 3 has Japanese support. However, when I tried to get Japanese datetime format with Date.toLocaleDateString(), it...
    2. I want to return an array instead of a query
      Dear Forum, My Flash program uses a web service connector that connects to a CFC. Everything works well with "return type="query. Now, I would...
    3. date query problem, date in variable
      I am using the following query : $query_archief = "SELECT * FROM vacatures where dd_eind_plaatsing < $dd_eind_plaatsing_archief1" note:...
    4. query to return table structure
      hi, Is there any command or query that returns the table structure informix.
    5. Using an asp page to return a sql query
      I know that there must be a way to do this, but in my limited knowledge I am stuck. I am using 2 tables 1. "BTstatus" BugIndex Date Entered...
  3. #2

    Default Re: SQL Query not return date if we use <> operators

    I have always had trouble using cf_sql_date in cfqueryparam, I have always had
    to use cf_sql-timestamp

    But this has been in cf 5

    I would suggest (for testing)
    change the where clause to
    WHERE StartingDate >= #CreateODBCDate(dtExpense)#

    If this works correctly, then try cahning the cfsqltype in the cfqueryparam
    and see if that works.

    Ken


    The ScareCrow Guest

  4. #3

    Default Re: SQL Query not return date if we use <> operators

    Thank's for your propositions but - unfortunately - it does not working. But,
    here is the results:

    From the method with CreateODBCDate

    <cfquery name="qGetCurrencyRates" datasource="#Application.DSN#">
    SELECT *
    FROM currencyConversion
    WHERE StartingDate >= #CreateODBCDate(dtExpense)#
    ORDER BY StartingDate ASC
    </cfquery>

    The result from the output/debug was that:

    SELECT *
    FROM currencyConversion
    WHERE StartingDate >= {d '2005-02-04'}
    ORDER BY StartingDate ASC

    And for the method with CFQUERYPARAM, the result of the output was that:

    SELECT *
    FROM currencyConversion
    WHERE StartingDate >= ?
    ORDER BY StartingDate ASC

    So, I feel that the CreateODBCDate function was the closest one but how to
    relieve of the '{d' and the ending '}'?

    francois-yanick Guest

  5. #4

    Default Re: SQL Query not return date if we use <> operators

    So I assume that there was no recordset returned ?

    If the column "StartingDate" is of data type datetime in the database, then
    the following is correct.

    SELECT *
    FROM currencyConversion
    WHERE StartingDate >= {d '2005-02-04'}
    ORDER BY StartingDate ASC

    Ensure that there are records in the db that match this criteria.

    What was the query that you tried in query analyser ?

    Ken


    The ScareCrow Guest

  6. #5

    Default Re: SQL Query not return date if we use <> operators

    The query that I tried with success in Enterprise Manager was this one:

    SELECT *
    FROM currencyConversion
    WHERE StartingDate >= '2/4/2005'
    ORDER BY StartingDate ASC

    When I tried it from Enterprise Manager, it returns me few records so I assume
    it have to work!

    francois-yanick Guest

  7. #6

    Default Re: SQL Query not return date if we use <> operators

    I just noticed that the database record the date in this format 'm/d/yyyy'
    instead of 'yyyy-mm-dd' like what CreateODBCDate created. I remember that I
    have a problem in the past with the format of the date when I was using it to
    search the database. But, usually, I will receive an error message from
    ColdFusion which I do not have with the method of CreateODBCDate. But I think
    it is better to add this one as a remark in case it serve!

    francois-yanick Guest

  8. #7

    Default Re: SQL Query not return date if we use <> operators

    The fact that sql server displays the date as m/d/yyyy should not make any
    difference. As the date is not stored like this internally.

    So the code you have should work.

    Just a thought, but have you installed the sp3 for sql server ?

    If not this could be the problem.

    Otherwise, I'm afraid I can't help.

    Ken

    The ScareCrow Guest

  9. #8

    Default Re: SQL Query not return date if we use <> operators

    I too am finding it impossible to sort by date in my Acccess Database.

    <cfquery datasource="ranger" name="StoryQuery">
    Select *from stories where date > #01/01/2001#
    </cfquery>

    Creates an error
    and

    <cfquery datasource="ranger" name="StoryQuery">
    Select *from stories where date > #createodbcdate(01/01/2001)#
    </cfquery>

    Is processed as

    Select * from stories where date > {d '1899-12-30'}

    Which obviously isn't correct. Dateformat() does not change the results.

    any help?




    J?J Guest

  10. #9

    Default Re: SQL Query not return date if we use <> operators

    You get errors because you have the incorrect format

    The first should be as follows, notice the single quotes
    <cfquery datasource="ranger" name="StoryQuery">
    Select *from stories where date > '#01/01/2001#'
    </cfquery>

    The second should be, notice the double quotes
    <cfquery datasource="ranger" name="StoryQuery">
    Select *from stories where date > #createodbcdate("01/01/2001")#
    </cfquery>

    Ken



    The ScareCrow Guest

  11. #10

    Default Re: SQL Query not return date if we use <> operators

    You need quotes around string dates passed to Date functions.
    Select *from stories where date > #createodbcdate('01/01/2001')#
    Otherwise it gives you a date corresponding to the division result of 1/1/2001

    Francois, you're not trying to put dates into the db in "dd/mm/yy" format are
    you?


    OldCFer Guest

  12. #11

    Default Re: SQL Query not return date if we use <> operators

    I am not trying to push a year in two digits.

    But I got the solution. The final answer for that problem (only for MS SQL
    issue, not for Access) is to make sure that the MS-SQL Service Pack 3 is
    installed. After that, everything will be alright for this problem.

    francois-yanick Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139