Ask a Question related to Coldfusion Database Access, Design and Development.
-
RichardG #1
where clause as variable string
I'm building a where clause as a string based on submited form variables. As
long as the form variable is an INTEGER the query works fine. If it is a
charcter or character string I get the error: "Incorrect syntax near 'n' "
where "n" was the content of the form variable.
for example, when the form variable form.explain value is "n":
.....
<cfset w= " WHERE t_QUESTIONS.q_section = dbo.t_sections.sect_ID ">
<cfif form.explain neq"">
<cfset w = w & " and t_QUESTIONS.q_explain = '#form.explain#' " >
</cfif>
<cfquery name="q" datasource="mydsn">
SELECT t_QUESTIONS.q_ID, t_QUESTIONS.q_section, t_QUESTIONS.q_explain,
t_sections.sect_name, dbo.t_sections.sect_ID
FROM dbo.t_QUESTIONS, dbo.t_sections
#w#
</cfquery>
...
returns the error: Line 5: Incorrect syntax near 'n'.
Outputting the var #w# content to the screen shows:
WHERE t_QUESTIONS.q_section = dbo.t_sections.sect_ID and t_QUESTIONS.q_explain
= 'n'
which looks perfect, and the query displayed in the debugging screen is:
SELECT t_QUESTIONS.q_ID, t_QUESTIONS.q_section, t_QUESTIONS.q_explain,
t_sections.sect_name, dbo.t_sections.sect_ID FROM dbo.t_QUESTIONS,
dbo.t_sections WHERE t_QUESTIONS.q_section = dbo.t_sections.sect_ID and
t_QUESTIONS.q_explain = ''n''
This has to be something simple, I just can't figure out what it is. I really
need to get this to work, anybody have a clue about what's going on? (this is
MX7)
RichardG Guest
-
String to Variable
Need some help with the following: I want to use global Variable in a if statement . The name of the variable is 'made' from some text and the... -
How to replace a variable string within /* variable_string */ with x for each character in string?
How to replace a variable string within /* variable_string */ with x for each character in string? The string may span on multiple lines. for... -
Convertin string to variable name
HI guys actually i found the answer so here's it for u to read on exitFrame me global desc_c1p1 desc_c1p1 ="Chapter 1- Introduction" repeat... -
Help a newbie! How do I SELECT using a string as a WHERE clause?
Hi, I'm having a problem. I've found that running a recordset with the query: SELECT * FROM user; works fine, but as soon as I add a... -
Using variable in From clause
I want to write a T-Sql script that will cycle through all of the tables in a database and write the number of records in each table. I have the... -
jdeline #2
Re: where clause as variable string
There is a function called PreserveSingleQuotes( ) that should solve your problem. Check out [url]http://livedocs.macromedia.com/coldfusion/5.0/CFML_Reference/Functions184.htm#1110445[/url]
jdeline Guest
-
RichardG #3
Re: where clause as variable string
jdeline,
That did the trick - thanks very much!!
RichardG Guest



Reply With Quote

