Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

My SQL Error

Posted on 2011-03-18
6
Medium Priority
?
459 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

618 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