Solved

My SQL Error

Posted on 2011-03-18
6
449 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
[X]
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
  • 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

705 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