Solved

My SQL Error

Posted on 2011-03-18
6
439 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 142

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 15

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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using winfows 7 and 10 download en install MYSQL server from a batch 13 101
MySQL ERROR 1045 (28000) 2 62
PHP loop not working 4 54
Mysql Crashing Intermittently 16 78
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now