Concat string will NULL in mysql
Hi all,
I want to know is there any way to concat a string with NULL as in a table of my database there are some fields with "NULL" and I want to add some string like "Abc" with in all rows in that field like update tablename set post=CONCAT(post,"","Job") where id=234; Here id is primary key and now after running this if any row contains NULL in that post field then this update returns NULL otherwise ok. Now how to add string with NULL? |
Your qn is unclear.
SQL NULL is not a value, its 'flag' in the DB stating that there is no value (not a value) in that field. You cannot concatenate onto or with a NULL, its a meaningless statement. http://dev.mysql.com/doc/refman/5.0/...unction_concat "CONCAT() returns NULL if any argument is NULL." |
Hi thanks.
After posting here I too found that on mysql site after searching and As you said any operation with NULL returns NULL. Anyway, I wrote a php script to find out which records contained NULL value in that particular field and made update without concat function. |
Quote:
update tablename set post=if(post is null,"Job",CONCAT(post,"","Job")) where id=234; - :) |
Great. I didn't know that. So many things yet to learn.
I did with the command below as post field is null anyway. Wrote a php code to find which records post field is null and then Code:
update tablename set post="job" where id=234; |
Doc page for v3.23,4.0,4.1: http://dev.mysql.com/doc/refman/4.1/...ml#function_if
do read the Red boxed text here: http://dev.mysql.com/doc/refman/4.1/en/index.html |
Quote:
The IF statement is useful in many situations, as well as UNION and DUAL. My Tip of the day: I use the UNION when I am searching large tables on two keys, it's considerably faster. Consider: Code:
select * from MyTransactions Code:
( (select * from MyTransactions where Key1=123) |
All times are GMT -5. The time now is 10:34 AM. |