I'm getting an Error in my WHERE clause - seems sosimple.

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

  1. #1

    Default I'm getting an Error in my WHERE clause - seems sosimple.

    Maybe because I'm new to Cold Fusion, but I'm getting the following error when
    running this query for a report...

    "Error Executing Database Query.
    Line 11: Incorrect syntax near 'APPROVED'.

    Here's the query.... (NOTE: form.cbo_InventoryStatus = "APPROVED")

    <cfquery name="MyQuery" datasource="Database">
    SELECT * FROM dbo.tableName
    <cfif form.cbo_InventoryStatus IS NOT "">
    <cfset WhereClause = WhereClause & " WHERE Asset_Status_Feature = '"
    & #form.cbo_InventoryStatus# & "'>
    </cfif>
    <cfoutput>#WhereClause# </cfoutput>
    </cfquery>


    The above doesn't work - however what's weird is that if I pass a Integer it
    works - such as below.
    <cfif form.cbo_Client NEQ 0>
    <cfset WhereClause = WhereClause & " WHERE ClientID = " & #form.cbo_Client#>
    </cfif>


    HELP!!!


    CarlMarket Guest

  2. Similar Questions and Discussions

    1. ERROR 1054 (42S22): Unknown column 'sul._limit' in 'having clause'
      mysql> describe s1_user_limits; +--------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default |...
    2. Simple WHERE clause in CFQUERY Has error executingdatabase query
      Hello, I'm sort of new to CF, but have been doing this enough that this is very frustrating! I'm using the standalone version of ColdFusion 6.1 on...
    3. Using IN in a WHERE clause
      I'm trying to use IN in a WHERE clause as follows: idx_res.city IN ('#session.s_city#') The value of session.s_city is 'highlands ranch, lone...
    4. CF MX 6 WHERE Clause
      Hi everyone! I keep getting the following error when I submit an update form for processing Macromedia] Too few parameters. Expected 1. The error...
    5. Syntax error in FROM clause
      We just installed CFMX on a Windows XP server. A datasource was defined using the Microsoft Access with Unicode. Certain queries run just fine,...
  3. #2

    Default Re: I'm getting an Error in my WHERE clause - seems sosimple.

    CF will automatically escape the single quotes, so you need to use
    PreserveSingleQuotes(string_variable)
    Ken


    <cfquery name="MyQuery" datasource="Database">
    SELECT * FROM dbo.tableName
    <cfif form.cbo_InventoryStatus IS NOT "">
    <cfset WhereClause = WhereClause & " WHERE Asset_Status_Feature = ' " &
    #form.cbo_InventoryStatus# & " ' ">
    </cfif>
    <cfoutput>#PreserveSingleQuotes(WhereClause)# </cfoutput>
    </cfquery>

    The ScareCrow Guest

  4. #3

    Default Re: I'm getting an Error in my WHERE clause - seems sosimple.

    NEW ERROR
    As a test I just hard coded the SQL Query and now I get this error...

    The value "" cannot be converted to a number

    See code (Thanks!)

    <cfcomponent>
    <cffunction name="ReportQuery" returntype="query" output="no" access="public">
    <cfset var MyQuery="">
    <cfset var WhereClause="">

    <!---
    Main.cfr expects the query passed into it to contain the following column
    names:
    Field: Asset_Status DataType: String
    --->
    <cfquery name="MyQuery" datasource="DatabaseName">
    SELECT * FROM dbo.TableName WHERE Asset_Status = 'APPROVED'
    </cfquery>
    <cfreturn MyQuery>
    </cffunction>
    </cfcomponent>

    CarlMarket Guest

  5. #4

    Default Re: I'm getting an Error in my WHERE clause - seems sosimple.

    What data type is Asset_Status, the error would indicate it is either a bit column or an integer ??

    Ken
    The ScareCrow Guest

  6. #5

    Default Re: I'm getting an Error in my WHERE clause - seems sosimple.

    That's what I thought too - but CF displays the datatypes above and it shows it's a string
    <!--- Field: Asset_Status DataType: String --->

    Thanks
    CarlMarket Guest

  7. #6

    Default Re: I'm getting an Error in my WHERE clause - seems sosimple.

    I would be checking the actual database.
    I would also test this query against the database outside of CF

    Ken
    The ScareCrow Guest

  8. #7

    Default Re: I'm getting an Error in my WHERE clause - seems sosimple.

    So what is the actual field name that you want to use? Your intial post
    referred to Asset_Status_Feature but your more recent posts refer to
    Asset_Status. Could it be possible that your database has both fields, where
    Asset_Status_Feature is a string and Asset_Status is numeric?

    Phil

    paross1 Guest

  9. #8

    Default Re: I'm getting an Error in my WHERE clause - seems sosimple.

    Here's what I ended up using which worked (thanks for all the help)

    <cfif Form.cbo_InventoryStatus IS NOT "">
    WHERE ((Asset_Status_Feature = <cfqueryPARAM value =
    "#Form.cbo_InventoryStatus#"
    CFSQLType = "CF_SQL_VARCHAR">) OR (Asset_Status_Episode = <cfqueryPARAM
    value = "#Form.cbo_InventoryStatus#"
    CFSQLType = "CF_SQL_VARCHAR">) OR (Asset_Status_VAM = <cfqueryPARAM value
    = "#Form.cbo_InventoryStatus#"
    CFSQLType = "CF_SQL_VARCHAR">) OR (Asset_Status_Audio = <cfqueryPARAM
    value = "#Form.cbo_InventoryStatus#"
    CFSQLType = "CF_SQL_VARCHAR">) OR (Asset_Status_Subtitle = <cfqueryPARAM
    value = "#Form.cbo_InventoryStatus#"
    CFSQLType = "CF_SQL_VARCHAR">) OR (Asset_Status_Menu = <cfqueryPARAM value
    = "#Form.cbo_InventoryStatus#"
    CFSQLType = "CF_SQL_VARCHAR">))
    </cfif>

    CarlMarket 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