Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / May 2008



Tip: Looking for answers? Try searching our database.

Cannot mix types VARCHAR and DOUBLE

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TiGGi - 23 Feb 2008 21:58 GMT
Hi all,

I got a bit of the problem here, I am doing zip code radius and trying to
return the results to a select box.
I want to display city, state, zip and distance in the select box and that's
where I get the problem.
So in my search page I got zip and radius field that bind to a cfc that gets
the data once those 2 fields are entered and returns it to the select box
(cfselect)
so in my cfc I have query that queries the original query in order to combine
the fields so I can bind it to the select box:
<cfquery ...>
select zipcode, (city + ', ' + state + ' - ' + zipcode + distance ) as
location,
</cfquery>
It''s not letting me mix my data with distance and giving me error:
Query Of Queries runtime error.
Cannot mix types VARCHAR and DOUBLE in a + binary operation.

Anyone knows how to avoid  this??????
-==cfSearching==- - 24 Feb 2008 00:25 GMT
[i] I have query that queries the original query in order to combine the
fields so I can bind it to the select box[/i]

Why not do this in the original query?  

[i] (city + ', ' + state + ' - ' + zipcode + distance ) [/i]

If the parenthesis ( ) are part of the result string, they should be enclosed
in quotes.  ' ( '+ city ...... +'  ) '

[i]Cannot mix types VARCHAR and DOUBLE in a + binary operation.[/i]

When using + with a mix of varchar and double/numeric values, CF may not
understand what you are trying to do.  It might get confused about whether you
are trying to concatenate strings or add numbers.  Using an explicit CAST to
convert the numbers to VARCHAR should prevent that problem.  That said, QoQ can
still be "quirky" at times.
TiGGi - 24 Feb 2008 02:31 GMT
thanks allot, that's exactly what I need, you da man!!!!!!
One issue though, I had results ordered by distance and now that's a varchar it's not ordering it correctly, any idea how can I fix this?
-==cfSearching==- - 24 Feb 2008 04:05 GMT
You should still be able to order by distance.  Though you may have to add it to your SELECT list (ie as a separate column.   SELECT zipcode, distance, ... concatenated columns...
TiGGi - 24 Feb 2008 15:17 GMT
Well since the distance is varchar now it's sorting it as a character not a number so order would be something like 1,10, 11....2, 20, 21 instead of 1,2,3,.......
-==cfSearching==- - 24 Feb 2008 23:21 GMT
Include the column twice.  Once separately, and once as part of the total
'location' string.  But only convert the one used in the concatentation. Then
it will sort correctly and you probably do not need a QoQ.

SELECT  
zipcode, distance,
city + ', ' + ... + cast(distance  as varchar) as location
...
CFJen - 02 May 2008 16:02 GMT
I'm running into the same issue but my datatype is datetime.  

Does anyone know how to do the same thing but with a datetime field? with the
format:  dd-mmm-yy.  I have tried CAST() but this returns the full date and
time stamp.  I'm unable to get date formatting for the field.  

Any help greatly appreciated.

Thanks in advanced,
Jennifer
CFJen - 02 May 2008 16:02 GMT
I'm running into the same issue but my datatype is datetime.  

Does anyone know how to do the same thing but with a datetime field? with the
format:  dd-mmm-yy.  I have tried CAST() but this returns the full date and
time stamp.  I'm unable to get date formatting for the field.  

Any help greatly appreciated.

Thanks in advanced,
Jennifer
JR "Bob" Dobbs - 02 May 2008 16:19 GMT
CFJen,

Options:
1. Don't format the date field in your query, using the DateFormat function in
your CF code to handle formatting when a date is displayed

2. To keep a formatted date in your query create a separate varchar field for
it. This was previously suggested by cfSearching for TiGGi's issue.

If this doesn't help please post your code and what you are trying to
accomplish, and any error messages you are receiving.
CFJen - 02 May 2008 19:17 GMT
Thank you JR 'Bob' Dobbs,

I created an alias in the one query, converting the datetime to varchar and then concatenated it in the query of queries.

Jennifer
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.