CFQUERY where '

I have a regular cfquery which is fine.
The problem I encountered is that an entry in the database I search by contains ',.
It seems so that something like
< CFQUERY...
Select * from table
WHERE to stay = 'Mike House'
< / CFQUERY >
of course "Mike is by closing the opening. I can not change the data in the db, so is it possible to make this work?

I JS line where it says html var = "#house #

Do you have data with double quotes in it? If you don't you can
out with the html var = "#house # CF allows nesting of quotations.

If you have data with single and double quotes, you need to
use the escape sequences. That those who are dependent on you technology
in collaboration with. I think that the for JS escape character is the backslash.

You can also use functions of coding such as URLEncodedFormat().

Tags: ColdFusion

Similar Questions

  • the analysis of a field in the CFQUERY WHERE clause

    I have a fairly large database that I need to execute queries.  I have a field that represents where store items are stored by aisle, section and bin. This field is concatenated with delimiters to underscore: aisle_section_bin.  An example of location can be 3_25_17.

    I need to execute queries where I analyze this location concatenated field and essentially ask:

    SELECT *.

    OF MyData

    Driveway WHERE = '3', section ' 25 "AND bin = '1'

    Could someone help me please with home, what would that be?

    My database is quite large, so I need my queries to be efficient enough so my server has no time-out.

    Thank you

    couldn't you just concatenate the values together as a string of CF and pass in your where clause:

    WHERE aisle_section_bin =

  • Using variables in sql, unexpected results queries coldfusion.

    I came across a somewhat embarrassing problem. I'd be interested to see if the following works for other people:

    < cfset sql_var "'something', 'something'" is >
    < = 'test' datasource cfquery name = "db" >
    Select id from table where unnom (#sql_var #)
    < / cfquery >

    Because it is that which produces a sql error - coldfusion tries to run the query in the form

    Select id from table where unnom in ("something", "thing")

    It is with the double quotes around each of the strings, even if it has not been specified in the sql_var variable.

    So I tried this:

    < cfset sql_var = "something","something else" > ".
    < = 'test' datasource cfquery name = "db" >
    Select id from table where unnom in (' #sql_var # ')
    < / cfquery >

    Where the sql_var variable has that single quotes between the two strings, and I added the quotes to the select statement. It produces no error, but no results either. Running sql is

    Select id from table where unnom ('something', 'something')

    Which is exactly as it should. I copy and paste the exact same query into the database and it produces results - but when coldfusion runs the query it doesn't. Executes the query with without product quotes a sql error, which is what I expect wopuld.

    Which leaves me somewhat at a loss. Anyone got any ideas?

    Running CF 6.1 (I think) using a database MySQL, if that makes a difference to anything.

    It is with the double quotes around each of the strings, even if it has not been specified in the sql_var variable.

    In Coldfusion, 'something' and 'something' are the same thing. You should expect that Coldfusion could pass from one to the other.

    Where the sql_var variable has that single quotes between the two strings, and I added the quotes to the select statement. It produces no error, but no results either. Running sql is
    Select id from table where unnom ('something', 'something')

    I don't think that it is running the query. Before moving on to the string, "something", "something else" to the Coldfusion query will automatically escape the single quotes on either side of the comma. This is the default behavior. The resulting query is

    Select id from table where unnom in (' something "," something else "")

    To avoid these complications, use the PreserveSingleQuotes() function. Therefore,.



    Select id from table where unnom in (#preservesinglequotes (sql_var) #)

  • How can I extract a substring in WHERE Clause &lt; CFQUERY &gt;?

    Is it possible to extract a substring in the WHERE clause of either < CFQUERY > or in a query of queries?  I try to use the following query to find all e-mail addresses with the domain "comcast.net" (i.e., everything that follows the '@' in the email address).  I ask an MS-Access database table.

    < cfquery name='test' datasource='membership'>
    SELECT Email_address
    OF tblMembers
    WHERE the MID (email_address, INSTR (email_address, ' @') + 1) = "comcast.net"
    < / cfquery >


    If I try this as a query, I get the error message "[Macromedia] [SequeLink JDBC Driver] [ODBC Socket] [Microsoft] [ODBC Microsoft Access driver] data type incompatible in criteria expression."


    If I try it as a t/t, I get the error message " " Met 'MID (e-mail1.,. Incorrect conditional expression, waiting for one of [as | null | between | in | comparison] condition,'.

    I would be very grateful for any help on finding something that works!  Thanks for your help!


    You couldn't do a LIKE in where clause instead:

    SELECT Email_address

    OF tblMembers

    WHERE email_address LIKE ' %@comcast.net'

    You should get the addresses you're looking for.

    -Carl V.

  • T/t with the WHERE clause using a list breaks

    Hello, all,.

    I have a project where I need to use a list as part of the WHERE clause for a t/t, and it is breaking.  I don't know what I'm doing wrong.

    For some pseudo-code, do I have a complete query of a database called 'people '.  A list of values for the t/t with the first query; the second query is my t/t:

    <cfquery name="getDIR" datasource="#request.THISDSN#">
        SELECT thisName dir FROM orgs WHERE thisID in (<cfqueryparam value="#form.org#" cfsqltype="cf_sql_varchar" list="yes" />)
    </cfquery>
    
    <cfquery name="people" database="people">
        SELECT colA, colB, colC, colD
        FROM people
        WHERE 1=1
            AND (
                div IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />)
                OR dir IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />)
                )
    </cfquery>
    
    
    

    I get the error message is "t/t syntax error: encountered" div IN \'thisValue\' ".»  Incorrect conditional expression, waiting for one of [as | null | between | in | comparison] condition. »

    Can support _not_ QoQ lists of WHERE clauses?

    V/r,

    ^_^

    SMH - so much... I just found.

    I forgot to give the lists in the second query bracket.


    (The pseudocode was manually typed, since my dev system is isolated from the internet, and I added the in my pseudo code when they were not in my original code.)

    * headdesk * headdesk * headdesk * headdesk *.

    V/r,

    ^_^

  • How do I add 7 days to a date and compare it to the current date in a cfquery?

    I have classes that are no longer active once after the date of the class. However, the class should be displayed for seven days more in the backend. I tried to use the script below to get there, but I get an error "Variable DATE is not defined." I'm going in the right direction or is there a better way to do this?

    < name cfquery = "getClasses" datasource = "#application.dsn #" >

    Select *.

    (break the classReg INNER JOIN classReg.classID = classes.classID) INNER JOIN instructors ON classreg.instID = instructors.instID

    <!-adding seven days to the date of the class (date) by comparing the current date->

    where #DateFormat (DateAdd (would be ', 7, date), 'yyyy-mm-dd') # > #DateFormat (now (), 'yyyy-mm-dd') #.

    < / cfquery >

    where #DateFormat (DateAdd (would be ', 7, date), 'yyyy-mm-dd') # > #DateFormat (now (), 'yyyy-mm-dd') #.

    As Coldfusion said you, quite rightly so, he knows no variable called "date". You're in a request and, apparently, 'date' is a column name. So use the SQL functions instead of Coldfusion functions.

    In MySQL, the appropriate where clause is:

    WHERE DATE_ADD (date, INTERVAL of 7 DAYS) > CURDATE)

    In SQL Server, the appropriate where clause is:

    WHERE DATEADD(day,7,date) > GETDATE()

    ---------------------------------

    Afterthought: I would rename the column 'date', as it is a reserved word in some database management systems

  • cfquery's caching question

    I have a question (actually two) about how caching works with cfquery so I can make sure that what I'm doing on our Web site is logical. (We're on CF10)

    I have a database that stores some details on each of the web pages on our site.  Contact ID, title, date added/updated, whether a recent article or recommended, etc.  The unique identifier for each page is the path (/ folder/subfolder/page.cfm).  Because the site is organized into several major themes, there is a column to identify which page is in the subject (and it is the same as the name of the folder that set of pages is located in).

    Some subjects have tons of hits and some receive very little, so I did this:

    <cfquery name="getalltopics" datasource="dsn" cachedwithin="#createtimespan(0,1,0,0)#">
    SELECT (columns I need
    FROM pages
    WHERE topic = <cfqueryparam value="#topicname#"  cfsqltype="cf_sql_varchar">
    </cfquery>
    
    <cfquery name="getpagedetails" dbtype="query">
    SELECT (columns I need)
    FROM getalltopics
    WHERE page_id = <cfqueryparam value="#page_path#"  cfsqltype="cf_sql_varchar">
    </cfquery>
    

    So here's my question.  I know that caches come into play if the query is running the same matches that is cached. So, in my mind, the fist query would make an individual of each of our subjects, cache as the pages were viewed during the day.  My second cache would grasp the details of the page of the first, with several topics being cached, how the other would know who find the details of the page in the cache?  The query works and is fast, but I wonder if I need to specify the topic ID in the second query.

    My second question is about the cache time.  If I don't createtimespan (0,1,0,0), that caches last an hour after its creation, or it doesn't last because an hour after the last time that this query is executed?

    Thank you!

    What I ended up doing was creating a query name based on a variable, named according to the topical, as follows:

    
    
    
    SELECT (columns I need)
    FROM pages
    WHERE topic = 
     
    
    
    SELECT (columns I need)
    FROM #qname#
    WHERE page_id = 
    
    

    In this way, I have (in theory) have a single cache for each topic, and my second query draws from this cache.

    The implementation, I noticed a significant reduction of hits to the database (because we still use that access to this site, no matter what hit creates an .ldb file, so I can easily tell if it's getting hit).  Before the change, the ldb file basically stayed there, appearing and reappear several times per second.  Now, several minutes can go with any ldb, even at the height of the day, and pages are surrendered almost instantly.  If I add up all my time to query for a page, I get 5 to 7 total ms.

    So, he must do something.

  • Using cfif in a where clause clause

    Hi all

    This question is somewhat related to a previous post of mine on the polling dates.  I'm trying to use a cfif statement in my where clause to determine if a field is empty or not.  Here is the code:

    < cfquery name = "GetPastEvents" datasource = "DSN" >

    SELECT *.

    SITE: calendar

    WHERE DatePart ("yyyy", [StartDate]) = < cfqueryparam value = ' #Dateformat (Today, 'yyyy') # "cfsqltype = 'CF_SQL_DATE' / >

    and < cfif EndDate NEQ "> < cfelse > StartDate, EndDate < / cfif > < < cfqueryparam value =" "#Today #" cfsqltype = 'CF_SQL_DATE' / > "

    and Archive = < cfqueryparam value = '0' cfsqltype = "CF_SQL_INTEGER" / >

    ORDER BY StartDate ASC, StartTime ASC

    < / cfquery >

    My question that this CF tells me EndDate is not defined.  EndDate is a field in the SITE table: calendar.  There must be a way to make this work, no?  Thank you!

    You mix the ColdFusion variables (required by cfif) and SQL column names. Think of it this way, all CF tags and function run before the SQL query is sent to SQL server. You are this mixture and try to run CF instruction on SQL Server and thus fail.

    You need something like this:

    SELECT *.

    SITE: calendar

    WHERE DatePart ("yyyy", [StartDate]) =

    and)

    (enddate is not null and EndDate <> )

    or (enddate is null and StartDate <> )

    )

    and Archive =

    ORDER BY StartDate ASC, StartTime ASC

    Also, I think your logic cfif was back. Instead of NEQ I think you meant EQ because having an EndDate EQ "and then comparing EndDate until today (else clause) makes no sense.

  • Selects related and showing CFQUERY value

    I have a form that works well. Using a CFC, I have two CFSELECTS that are related. A selection on the first determines the display on the second. So far so good. But then I started thinking that users must remember what they choose. In the first CFSELECT, the value is a user ID. I want to use it to fill a CFINPUT or simply a CFOUTPUT, but this must be linked to the CFSELECT. If the user chooses his name. Fills a second CFSELECT with choice so she can choose. But in the meantime, I want to show a choice she made months ago, and it's a value I caught in the CFFUNCTION that is related to that CFSELECT.

    Is there a way to display a different value after the CFSELECT? A value other than my CFQUERY in the CFC has already caught?

    It would be really nice. I could then, as soon as a user has chosen his name, show his user ID and other information, and also show him this selection of some material she made months ago and forgotten.

    Then the form would go to the second CFSELECT where she would pick a date for the service tech. But I think this part is irrelevant to what I want to do in the meantime.

    I googled this scenario and the most likely solution is something like that.

    Within a CFFUNCTION and a component, I would put something like that

    < cfset var userModel = [Nomrequete] .userModel > (I'm guessing here)

    < cfreturn userModel >

    And then I'd be able to bind a CFINPUT for this component and function and display the userModel.

    The user would see this and remember this that the material she chose and then continue to choose a date for it.

    I tried variations on it but still get a message indicating that the parameter was not passed.

    I got it. I just need to refer to the previous selection, like this. link = ':cfc.laptopModel.getModel({employeecfc}).

  • CF8 cfquery multiple table join with the same names of columns - default

    This seems to be a defect in the CF8 cfquery object. I'm at a loss as to a solution or a good work around. With regard to the substance, this query is generated dynamically on the fly based on what is happening in it a user. This isn't the most elegent SQL but work and return all columns. The app itself is a data viewer to look at the logs. Here is an example of a query being generated.

    Select *.

    of web_trans, web_info_trans, web_res_trans

    where (web_info_trans.trans_dte > = '' 2008-12-1)

    and web_info_trans.trans_dte < '' 2008-12-2)

    and (web_info_trans.trans_dte = web_trans.trans_dte)

    and (web_info_trans.trans_num = 5060345)

    and (web_info_trans.trans_num = web_trans.trans_num)

    and (web_res_trans.trans_num = 5060345)

    and (web_res_trans.trans_num = web_trans.trans_num)

    and (web_trans.web_trans_cde = "NTUI")

    and (web_trans.web_status_cde = 'P')

    and (web_trans. TRANS_NUM < 5060347)

    order of web_trans. TRANS_NUM / / desc

    These three tables contain a similar column called ZIP_CDE. They contain different values, and when this query is executed in Microsoft Query Analyzer results are displayed correctly. Run this same query SQL with CFQUERY and the value of one of the other tables (web_trans) will eventually replace the value for the other columns called ZIP_CDE. The exact amount columns are retruned only values some how get corrupted.

    This is a defect of cf8 is a book autour or an update that resolves this problem that I may have missed?

    Thank you for the ideas.

    Thus it seems still as a default since CF is essentially where, except for the return value play. Other query tools return results correctly so for me, it turns out be CF bug at a certain level.

    Actually I'm swinging to agree with you here, but not for the same reason.  CF actually * is * get all the columns back (as you say), it just doesn't expose a way to tell the difference between a column called 'x' and an another column called 'x', because the way to access the data in columns is simple queryname [columnName] [rowNumber] (or a Variant fo this, but all the amount of variations to that or abbrev. it).  This code shows how he has all four columns of the original two queries (being a stand-in for tables, in this case):


    Q1 = queryNew("");
    Q2 = queryNew("");
       
    queryAddColumn (q1, 'id', [1,2,3,4]);
    queryAddColumn (q1, "data", ["one", "two", "three", "four"]);
    queryAddColumn (q2, 'id', [1,2,3,4]);
    queryAddColumn (q2, "data", ["tahi", "rua", "toru", "wha"]); It's Maori, in case you are interested


    SELECT *.
    Q1, q2
    WHERE q1.id = q2.id

    So CF knows there are four columns (a call getMetadata (q3) get also demonstrates this), but it does not expose a way to approach the second (or even greater) column of the same name.  This is the bug/shortfall.

    However, relying on an underlying coldfusion.sql.QueryTable method, you can rename the columns, so:

    Then you're OK.

    I would be normally reluctant to recommend doing this, because these methods change from version to version of CF, but it's your call whether this approach will help you.

    To be honest, I'm with Owain who, even in SQL one generally doesn't work with columns with the same name, an alias them qualified with a table name/alias. As the table columns from of is not returned by SQL with the result set, it must be evidence against this by folding the columns in the first place.

    Also, I wonder at the bottom of the extraction of data, you don't really know the structure, that is to say, do SELECT *.  How can you know not even that is ours as the first column, second column, etc.?  I don't think that SQL applies in fact a contract that, t - it?  (I don't know).

    What are you actually do here?

    --

    Adam

  • Weird error in cfquery, cannot use cfelse in cfquery?

    < name cfargument = "StateID" type = "any" default = "" >

    < cfargument name = "LocationID2" type = "any" default = "" >

    < cfset var data = "" >

    < cfquery datasource = "" #ds # "name ="data">"

    SELECT s.State_ID s.State, l.Location_ID, l.Area, l.State_ID, r.Name, r.Location_ID

    FROM State s, location, Restaurants r

    WHERE 0 = 0

    AND r.Location_ID = l.Location_ID

    AND l.State_ID = s.State_ID

    < cfif #ARGUMENTS. LocationID2 # LT 9 >

    AND l.State_ID = (#ARGUMENTS. LocationID2 #)

    < cfelse >

    AND l.Location_ID = (#ARGUMENTS. LocationID2 #)

    < / cfif >

    This is the code in the component file, it works with a normal form with action.

    But when I try to do with ajax, something like < cfdiv bind = «...» ' >, we get error with

    58 :           AND l.St
    
    ate_ID = (#ARGUMENTS.LocationID2#)
    59 :           <cfelse>
    60 :                AND l.Location_ID = (#ARGUMENTS.LocationID2#)
    61 :           </cfif>

    but when I remove the cfelse, it works without any errors. I feel weird, can you please give me some advice?

    It's hard without the message error but just for fun, try to change your statement to the following:

    AND l.State_ID = #val (ARGUMENT. LocationID2) #.

    AND l.Location_ID = #val (ARGUMENT. LocationID2) #.

    If it works, then the caller of the function does not provide the LocationID2 argument and because your statement does not require a value and values by default for ' ', arguments. LocationID2 is not a number.

  • &lt; cfquery &gt; return type

    Hello

    < cfproperty >

    < name cffunction = "saveInfo" access = "public" returntype = "query" >
    < name cfargument = "Employe_id" type = "string" required = "no" >
    < name cfargument = "Address" type = "any" required = "no" >

    < cfquery name = "EmployeeInfo" datasource = "Employees_data" >
    Update Employees_Data_Info

    SET Address = ' #arguments. Address #'

    where Employee_ID = ' #arguments. Employe_id #'
    < / cfquery >

    < cfreturn EmployeeInfo >

    < / cffunction >

    < / cfproperty >

    It is throwing the following error.

    faultCode:Server.Processing faultString: 'Unable to invoke CFC - EmployeeInfo Variable is not defined.' faultDetail: "

    Can anyone suggest why it's happening...

    Thank you...

    Update queries from does not return a Recordset...

    --

    Adam

  • cfquery fails with conditional stored query in a variable

    Following the code does not work. Can anyone explain why?

    < cfset myquery = "select * from employee where id ="10 "" > "
    < name cfquery = "a" datasource = "MyDSN" >
    #myquery #.
    < / cfquery >

    What do you mean by "not working"?  You really should read this before posting: http://forums.adobe.com/thread/607238.

    The ID is really a column focused on the chain?  I expect it to be an integer, so it did not have quotes.

    Also, if you do what you do, if your variable inside single quotes, you will need to use preserveSingleQuotes() to stop CF escape them.

    --
    Adam

  • cfquery simple question - level amateur

    Hi all

    make a few simple changes to my Web site

    There is already a database running with a lot of query cfloop

    question is this:

    This code below retrieves the name of cake (#cake_name #) for line 1 in the database, but its using a loop

    < cfloop query = "cake_query" STARTROWOPTIONAL = "1" ENDROWOPTIONAL = "1" >

    #cake_name #.

    < / cfloop >

    How can I do this without the help of a loop?

    I thought that it ould be that simple:

    < cfquery = "cake_query" LINE = "1" >

    < / cfquery >

    but apparently not...

    also at the top of the code, there is already this code below, which I know works with queries of the loop, im assuming that I don't need to change for row queries?

    < name cfquery = "cake_query" datasource = "" #request.datasource # ""
    username = "" #request.username # "password =" #request.password # ">"
    SELECT * FROM gce_cakes where cake_active = 1 ORDER BY cake_number
    < / cfquery >

    Thanks in advance to anyone who can help

    If you want to access any element of a query, regardless of how many lines there, the format is:

    queryName.columnName [rowNumber]

    And if you want to print:

    #queryName.columnName [rowNumber] #.

    As for the question ... is to send the SQL strings and params to a driver of the DB and the conversion returned in a Recordset (accidentally referred to a "query" quite often in the attributes of language & CF tag).  does not care how many lines is returned from the database: 0... 1... more than one... she returns a recordset with that many lines in there.

    Make sense?

    --

    Adam

  • cfquery to javascript to .js file array

    Hi guys,.

    I have a little problem there:

    have cities table in the database so pulling outwards using cfquery.

    < name cfquery = "get_city" datasource = "IGES" >
    SELECT *.
    Cities
    ORDER BY city ASC
    < / cfquery >

    Now all these names of city of data must be sent to the file .js in a sort of table

    "< script type =" text/javascript"src ="... / jscripts/add_school.js "> < / script >"

    ^ ^ ^ This is the file all the javascript code is in

    Is it possible to pass an array of cfquery to the javascript file where it can be used to populate the listbox control.

    see you soon,

    Simon

    Of course, just build this JavaScript array in the answer sent to the client.

    Remember that CFML runs on the server and is done completely before whatever it is either sent to the customer have been JavaScript done its thing.

    ColdFusion provides support to achieve this.

    The tag as a parameter to directly convert complex variables CF variables complex JS.

    There is the more recent toScript() function.

    Or it is often quite easy to drive cleaner.

Maybe you are looking for