Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Typed CFQUERY vs passed variable CFQUERY

Posted on 2008-06-10
5
341 Views
Last Modified: 2010-04-21
Hi all,

I have an issue with a query I am trying to create and run. The query is compiled based on various criteria and saved into a variable. That variable is then passed to a CFQUERY like this:

<cfquery datasource="#datasource#" name="GetReportData">
    <cfoutput>#qryFull#</cfoutput>
</cfquery>

When run, I get the error "Incorrect syntax near ','." The funny thing is that the syntax is correct. when I output the variable I get the code included at the bottom of this message. When I copy and past that exactly in Query Analyser and run it against the same MSSQL database ColdFusion is using, it returns the expected results. Even when I copy and paste it into the ColdFusion page in place of the variable, it returns the expected results.

So the issue seems to be in the difference between how ColdFusion reads the text and reads the variable containing the same text.

Any ideas? See output query below:
SELECT patient.patientAccount AS patientpatientAccount, 
	CASE WHEN patient.companyName IS NULL OR LTRIM(RTRIM(patient.companyName)) = '' 
		THEN patient.lastName + ', ' + patient.firstName 
		ELSE patient.companyName 
		END AS patientpayeeName, 
	patient.address AS patientaddress, 
	patient.city AS patientcity, 
	patient.state AS patientstate, 
	patient.zip AS patientzip, 
	patient.phone AS patientphone, 
	transactions.amount AS transactionsamount, 
	transactions.transDate AS transactionstransDate, 
	CASE WHEN patient.companyName IS NULL OR LTRIM(RTRIM(patient.companyName)) = '' 
		THEN patient.lastName + ', ' + patient.firstName 
		ELSE patient.companyName 
		END AS patientpayeeName, 
	patient.dateOfBirth AS patientdateOfBirth, 
	doctor.businessName AS doctorbusinessName, 
	transactions.date_SentToCollections AS transactionsdate_SentToCollections 
FROM transactions WITH (NOLOCK) 
	LEFT JOIN patient WITH (NOLOCK) ON patient.patientID = transactions.patientID 
	LEFT JOIN doctor WITH (NOLOCK) ON doctor.doctorID = transactions.doctorID 
WHERE transactions.collectorID = 46 
	AND transactions.collectorExported = 0 
	AND transactions.active = 0 
ORDER BY transactions.transDate

Open in new window

0
Comment
Question by:msfletch
  • 3
  • 2
5 Comments
 
LVL 36

Expert Comment

by:SidFishes
ID: 21754499
try using

#evaluate("#de(qryFull)#")#
0
 
LVL 4

Author Comment

by:msfletch
ID: 21754589
SidFishes,

Using either:

#evaluate("#de(qryFull)#")#

or

#evaluate(DE(qryFull))#

... returns the same "Incorrect syntax near ','" error.

Any other thoughts?
0
 
LVL 36

Accepted Solution

by:
SidFishes earned 500 total points
ID: 21754841
it's the lines

THEN patient.lastName + ', ' + patient.firstName

you can either build the name in cf

<cfset name = q.lastname & ", " & q.firstname>

or do something like

I'm not 100% sure that will work since I don't have tables to test it against...but testing it threw a DB error so I think it cleared the parsing error

<cfsavecontent variable="x">
SELECT patient.patientAccount AS patientpatientAccount, 
        CASE WHEN patient.companyName IS NULL OR LTRIM(RTRIM(patient.companyName)) = '' 
                THEN patient.lastName + '~' + patient.firstName 
                ELSE patient.companyName 
                END AS patientpayeeName, 
        patient.address AS patientaddress, 
        patient.city AS patientcity, 
        patient.state AS patientstate, 
        patient.zip AS patientzip, 
        patient.phone AS patientphone, 
        transactions.amount AS transactionsamount, 
        transactions.transDate AS transactionstransDate, 
        CASE WHEN patient.companyName IS NULL OR LTRIM(RTRIM(patient.companyName)) = '' 
                THEN patient.lastName + '~' + patient.firstName 
                ELSE patient.companyName 
                END AS patientpayeeName, 
        patient.dateOfBirth AS patientdateOfBirth, 
        doctor.businessName AS doctorbusinessName, 
        transactions.date_SentToCollections AS transactionsdate_SentToCollections 
FROM transactions WITH (NOLOCK) 
        LEFT JOIN patient WITH (NOLOCK) ON patient.patientID = transactions.patientID 
        LEFT JOIN doctor WITH (NOLOCK) ON doctor.doctorID = transactions.doctorID 
WHERE transactions.collectorID = 46 
        AND transactions.collectorExported = 0 
        AND transactions.active = 0 
ORDER BY transactions.transDate
</cfsavecontent>
 
 
 <cfquery datasource="kdata" name="GetReportData"> 
   #evaluate(de(replace(x, "'~'", ", ", "ALL")))#
 </cfquery> 

Open in new window

0
 
LVL 4

Author Comment

by:msfletch
ID: 21754990
Thanks SidFishes!

Coming through again. That worked. So it seems as though CF has an issue passing single quotation marks from variable directly to a query. This was the same reason I was having trouble passing static variables through the query (see: QID 23462296) because they were also being passed to the cfquery through a variable.

So to recap, the final solution I used was (see attached):
<cfquery datasource="datasource" name="GetReportData">
<cfoutput>
    #evaluate(de(replace(qryFull, "', '", ", ", "ALL")))#
</cfoutput>
</cfquery>

Open in new window

0
 
LVL 4

Author Closing Comment

by:msfletch
ID: 31465844
Thanks again!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Airline check in kiosk 4 112
query of query sort 6 106
What is the new coldfusion video tag for CF 11 or CF2016 for HTML5 playback 3 52
cfhttp question if a directory exists 1 17
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question