Solved

My SQL Error

Posted on 2011-03-18
6
444 Views
Last Modified: 2012-05-11
I have the following query!

select DISTINCT (stores.id) as single, stores.name, c.styleid,
si.itemid, c.item_type, IFNULL(c.cost_retail,0), si.date_paid
from si
inner join stores on si.storeid = stores.storeid
inner join c on si.itemid = c.itemid

it runs perfect in Mysql editor when i run in cfquery i get the following error

Invalid CFML construct found on line 1 at column 37.
ColdFusion was looking at the following text:

''

The CFML compiler was processing:

    An expression beginning with var.IFNULL, on line 1, column 1.This message is usually caused by a problem in the expressions structure.



Please guide
0
Comment
  • 4
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35168876
please try COALESCE instead of IFNULL
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 35168891
I think you need to show more code, if that SELECT is inside a CFQUERY it seems like that is not where the error is happening because the error is a CF error not a database error

0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 35168906
here is my code!

<cfquery name = "qInventory" datasource="#dsn#">
select DISTINCT (stores.id) as single, stores.name, c.styleid,
si.itemid, c.item_type, IFNULL(c.cost_retail,0), si.date_paid
from si
inner join stores on si.storeid = stores.storeid
inner join c on si.itemid = c.itemid
WHERE date_paid >= #createodbcdate(start_date)#
</cfquery>
<cf_dump variable="qInventory">
<cfif qInventory.recordcount>
      <cfset c_sales = qInventory.recordcount>
    <CFSET cost_unit = #qInventory.cost_retail#>
<cfoutput>
<cf_dump variable="cost_unit">
</cfoutput>    
<cfelse>
      <cfset c_sales = 0>
    <CFSET cost_unit = 0>
</cfif>
<cfabort>

now the record comes to 7000, but my cost)unit shows "" i mean null value
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 39

Expert Comment

by:gdemaria
ID: 35168946
You need to use #s inside your cfdump

(You don't need them in the CFSET, but it didn't hurt anything)

<cfquery name = "qInventory" datasource="#dsn#">
  select DISTINCT (stores.id) as single, stores.name, c.styleid,
  si.itemid, c.item_type, IFNULL(c.cost_retail,0), si.date_paid 
  from si
    inner join stores on si.storeid = stores.storeid
   inner join c on si.itemid = c.itemid 
   WHERE date_paid >= #createodbcdate(start_date)# 
</cfquery>

<cf_dump variable="#qInventory#">
<cfif qInventory.recordcount>
    <cfset c_sales = qInventory.recordcount>
    <CFSET cost_unit = qInventory.cost_retail>
    <cf_dump variable="#cost_unit#">
<cfelse>
    <cfset c_sales = 0>
    <CFSET cost_unit = 0>
</cfif>
<cfabort>

Open in new window

0
 
LVL 39

Expert Comment

by:gdemaria
ID: 35168953
wait.. are you using your own custom dump tag?

cfDump has no _  and it's var =

<cf_dump variable="#qInventory#">

should be..

<cfdump var="#qInventory#">


Unless you have a custom tag called dump.cfm ??
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 125 total points
ID: 35168966


when using a function on a field, you should add an alias

select DISTINCT (stores.id) as single
     , stores.name
     , c.styleid
     , si.itemid
     , c.item_type,
     , IFNULL(c.cost_retail,0) as cost_retail   <======= add an alias  
     , si.date_paid
from si

0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

809 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