ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 11th, 2005, 01:46 PM
awdang_99 awdang_99 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 41 awdang_99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 33 m 25 sec
Reputation Power: 4
Concat two fields to create a date

Hello everyone,

I'm having problems with a query that combines two int(11) fields to make a date. The query works when run directly in MySQL, but it seems to not be understood by ColdFusion. Here's the line that I'm having problems with:

Date_Format(CONCAT(dataYear,'-',dataMonth,'-01'), '%Y-%m-%d') BETWEEN '2005-04-01' AND '2005-08-01'

I think ColdFusion is turning the concat portion into a string and not considering it as a date. Therefore, the query code fails. Can someone help me with this?

Reply With Quote
  #2  
Old August 11th, 2005, 02:50 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
ColdFusion shouldn't be doing anything to the query, but it could be a JDBC driver issue. All CF does is evaluate things between pound signs (variables, function calls, etc.), so it isn't doing anything to the code that you posted. Remember that all CF does is take the sQL statement and feed it to the data source via the JDBC driver...it doesn't "do" anything to the SQL statement in terms of processing.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old August 11th, 2005, 03:31 PM
awdang_99 awdang_99 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 41 awdang_99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 33 m 25 sec
Reputation Power: 4
I thought the same thing, but I've run into this on another occassion where I had to extract the hour of day from a datetime field. I had to use Hour() instead of DateFormat(date, '%H') because ColdFusion was expecting a different datatype. Once I made the change, then my calculations in my CF application began to work.

So, I'm thinking this is a similar thing, but I'm not sure how to resolve it. I've run the code a number of different ways directly in MySQL, and it runs properly. Here's the entire query for you to checkout. Maybe you can evaluate it and give me more feedback.
*************

SELECT CASE
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'ARS' THEN 'Archive Rec Sound'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'ART' THEN 'Art'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'BIO' THEN 'Bio'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'BRN' THEN 'EarthSci'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'CHM' THEN 'Chem'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'EAL' THEN 'East Asia'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'EDU' THEN 'Educ'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'ENG' THEN 'Eng'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'GAS' THEN 'ASRG'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'GHD' THEN 'HDIS'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'GHG' THEN 'HRG'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'GRN' THEN 'IC'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'GLO' THEN 'Loan'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'GMM' THEN 'Media Micro'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'GSP' THEN 'Spec'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'GSD' THEN 'SSDS'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'GSR' THEN 'SSRC'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'HOP' THEN 'Hopkins'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'LAN' THEN 'Lane'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'LAW' THEN 'Law Library'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'MAT' THEN 'Math'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'MUS' THEN 'Music'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'PHY' THEN 'Physics'
WHEN SUBSTRING(RS.AggregateID, 1, 3) = 'SAL' THEN 'SAL'
END AS 'Library',
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '01', RS.Count,0 ) ) AS Directional,
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '02', RS.Count,0 ) ) AS Inquiry,
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '03', RS.Count,0 ) ) AS Strategy,
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '04', RS.Count,0 ) ) AS Tutorial,
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '05', RS.Count,0 ) ) AS ResAssistance,
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '12', RS.Count,0 ) ) AS Reference,
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '13', RS.Count,0 ) ) AS TechAssistance,
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '01', RS.Count, 0 )) +
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '02', RS.Count, 0 )) +
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '03', RS.Count, 0 )) +
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '04', RS.Count, 0 )) +
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '05', RS.Count, 0 )) +
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '12', RS.Count, 0 )) +
SUM(IF ( SUBSTRING( RS.AggregateID, 8, 2 ) = '13', RS.Count, 0 ))
AS Total
FROM ReferenceStatistics RS
WHERE SUBSTRING(RS.AggregateID, 8, 2) NOT IN ('00','07','08','09')
AND (
(
Date_Format(CREATED_DT, '%Y/%m/%d') BETWEEN '2005/01/01' AND '2005/08/01'
AND InputMethod = 2
)
OR
(
DATE_FORMAT(concat(dataYear,'-',dataMonth,'-01'), '%Y-%m-%d') BETWEEN '2005-01-01' AND '2005-08-01'
AND InputMethod = 1
)
)
GROUP BY CASE
WHEN SUBSTRING(RS.AggregateID, 1, 3) <>'' THEN SUBSTRING(RS.AggregateID, 1, 3)
END
WITH ROLLUP;
*************************

Thanks

Reply With Quote
  #4  
Old August 11th, 2005, 04:03 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 33 m 51 sec
Reputation Power: 53
That's the thing, hour() and dateFormat() are both ColdFusion functions. The functions you are using in your query are MySQL functions. So there's nothing that CF would be doing to the SQL statement besides sending it, as it is, to the JDBC connection.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Concat two fields to create a date


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT