views:

169

answers:

3

hello, i want update my row and concat my string but i have an error with this query

UPDATE FILE SET NOMFIC ='supp_'+D_NOMFIC WHERE IdFile = 2
A: 

You can't concat with + in MySQL. Use CONCAT('supp_, D_NOMFIC), so it becomes UPDATE FILE SET NOMFIC = CONCAT('supp_, D_NOMFIC) WHERE IdFile = 2

For more info see: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat

You can concat quoted strings like this: SELECT 'a' 'b' 'c' FROM someTable though.

Snake
i want to get my string and concat with 'supp' and do update
Mercer
if D_NOMFIC is 'blah' than the result will be 'supp_blah'
Snake
yes but not working with this method
Mercer
D_NOMFIC doesn't exist? What's the column's name?
Snake
A: 
UPDATE FILE SET NOMFIC = CONCAT('supp_',NOMFIC) WHERE IdFile=2;

See the CONCAT() function within the MySQL documentation here

CONCAT() basically takes as its parameters a list of strings to be concatenated together.

Mailslut
#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET NOMFIC =CONCAT('supp_',D_NOMFIC)
Mercer
@Mercer: that works for me fine. You should be doing something else wrong
Cristian
#1054 - Unknown column 'D_NOMFIC' in 'field list'
Mercer
@ mercer - it seems to work fine for me here, i just tried it.
Mailslut
@mercer, you have the field D_NOMFIC in your original question. I'm guessing you just meant NOMFIC. If so, this is what you want:UPDATE FILE SET NOMFIC = CONCAT('supp_',NOMFIC) WHERE IdFile=2;
Mailslut
yes work sorry thx all for your response ;)
Mercer
A: 

Try this:

UPDATE FILE SET NOMFIC = CONCAT('supp_', D_NOMFIC) WHERE IdFile = 2

Cristian
#1054 - Unknown column 'D_NOMFIC' in 'field list'
Mercer