473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CONCAT with IF

Damn it this "illegal mix of collashit" messages are driving me nuts!!

What's wrong with the following statement?

SELECT userid, CONCAT(username,' / ',firstname,' ',lastname,' / ',
email, IF(activated=1,'',' (NOT YET ACTIVATED)')) AS uname FROM tbuser

I get:

MySQL Error Occured
1271: Illegal mix of collations for operation 'concat'

Same error if I try CAST'ing "activated" to CHAR

SELECT userid, CONCAT(username,' / ',firstname,' ',lastname,' / ',
email, IF(CAST(activated AS CHAR)='1','',' (NOT YET ACTIVATED)')) AS
uname FROM tbuser

Nov 23 '05 #1
3 13704
ni******@hotmail.com wrote:
Damn it this "illegal mix of collashit" messages are driving me nuts!!

What's wrong with the following statement?

SELECT userid, CONCAT(username,' / ',firstname,' ',lastname,' / ',
email, IF(activated=1,'',' (NOT YET ACTIVATED)')) AS uname FROM tbuser


Tested with MySQL version 4.0, it worked fine.
mysql> create table tbuser ( userid int, username text, firstname text,
lastname text, email text, activated int );
Query OK, 0 rows affected (0.01 sec)

mysql> insert into tbuser values(1,'jt','jack','tailor','j*@jt.invalid',1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into tbuser values(2,'lt','lisa','tailor','l*@jt.invalid',0);
Query OK, 1 row affected (0.01 sec)

mysql> SELECT userid, CONCAT(username,' / ',firstname,' ',lastname,' / ',
-> email, IF(activated=1,'',' (NOT YET ACTIVATED)')) AS uname FROM
tbuser;
+--------+------------------------------------------------------+
| userid | uname |
+--------+------------------------------------------------------+
| 1 | jt / jack tailor / jt@jt.invalid |
| 2 | lt / lisa tailor / lt@jt.invalid (NOT YET ACTIVATED) |
+--------+------------------------------------------------------+
2 rows in set (0.00 sec)
Nov 23 '05 #2
ni******@hotmail.com wrote:
MySQL Error Occured
1271: Illegal mix of collations for operation 'concat'


Just a guess, but I'd try using the BINARY operator to cast your char
fields to binary strings, so that the arguments of CONCAT are compatible.

See http://dev.mysql.com/doc/refman/5.0/...functions.html

I'm not sure I can offer specific usage suggestions, I'm not experienced
with character sets and collations and stuff. See what you can learn
from the docs.

Regards,
Bill K.
Nov 23 '05 #3

Bill Karwin wrote:
ni******@hotmail.com wrote:
MySQL Error Occured
1271: Illegal mix of collations for operation 'concat'


Just a guess, but I'd try using the BINARY operator to cast your char
fields to binary strings, so that the arguments of CONCAT are compatible.

See http://dev.mysql.com/doc/refman/5.0/...functions.html

I'm not sure I can offer specific usage suggestions, I'm not experienced
with character sets and collations and stuff. See what you can learn
from the docs.

Regards,
Bill K.


Well what do ya know... I did try BINARY without working but
re-arraging fix it:

SELECT userid, CONCAT(username,' / ',firstname,' ',lastname,' / ',
email, CAST(IF(activated=1,'', (NOT YET ACTIVATED)') AS BINARY)) AS
uname FROM tbuser

Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gerald Aichholzer | last post by:
Hello, I need to specify the following attribute in an xhtml-file containing TAL templates: <div tal:attributes="onMouseOver concat('func(',xyz,')')"> which results in <div...
5
by: F. Da Costa | last post by:
Hi, Could it be correct that the following code does *not* work because i'm not using the var arr = new Array("a","b","c"); methodology?? Read through...
3
by: Bryan Valencia | last post by:
Ok, I tried to use the concat function. It's in the Help, but it claims it can't find the namespace that contains 'concat'. You'd think there'd be a note in the help system if I have to use some...
16
by: Jacky | last post by:
Hi, Concat wors as tmpStr = tmpStr.Concat(tmpStr, tmpStr2) Why it do not refer to owner object so tmpStr.Concat(tmpStr, tmpStr2) and now tmpStr has same value as upper?
8
by: Doug Stiers | last post by:
Is there a downside to using string.concat? Other than a little overhead? str1 = string.concat(str1,str2) vs. str1 &= str2 It seems to me like the string class should be optimized to do this...
4
by: Martin Fletcher | last post by:
I cant get the Concat function to work, please help. Here's some of my code. Module modTCP Public TCP_RECEIVED_DATA As String Private WithEvents TCP_SERVER As New WinSockSVR Private Sub...
1
by: Trint Smith | last post by:
Ok, I have a webform that has these checkboxes: 1. something 2. something else 3. and something else When the user clicks on the checkbox, I want all of the selections to go into a textbox...
3
by: Mythran | last post by:
Out of curiosity, only, which is recommended for SHORT concatenation...or concatenating two or three strings that are relatively small in size? Dim a As String = "bah" Dim b As String = "bah2"...
4
by: Martin Evans | last post by:
Hi, I'm getting: DBD::DB2::db do failed: SQL0440N No authorized routine named "CONCAT" of type "FUNCTION" having compatible arguments was found. SQLSTATE=42884 for some SQL like this:
6
by: antmail | last post by:
Hi guys, I have spend several days now trying to solve this problem inside a stored procedure. I want to call a procedure providing 3 variables. The variables area used to select the appropriate...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.