tags:

views:

110

answers:

3

Hello, I need to copy a row .
Copied row,I need to change value, this value + 'copy' I made this sql..but it's not work..

INSERT INTO prizes_i18n (
  lang_id
  , translation_name
  , translation_desc
  , name
  , lang_path)
SELECT  prizes_s.lang_id
        , prizes_s.translation_name +  'copy'
        , prizes_s.translation_desc
        , prizes_s.name
        , prizes_s.lang_path   
FROM    prizes_i18n prizes_s 
WHERE   prizes_s.lang_id = 637; 

Without + 'copy' its works. Like this prizes_s.translation_name + 'copyy',but it's not work.

+6  A: 

From this previous question you use MySQL? If so use concat for string concatenation.

SELECT 'foo' + 'bar' ...

Returns 0 in MySQL which would explain the error about doubles you are seeing.

INSERT INTO  prizes_i18n (lang_id, translation_name, translation_desc, 
                          name, lang_path)
SELECT  prizes_s.lang_id,
    concat(prizes_s.translation_name, 'copy'),    
    prizes_s.translation_desc, prizes_s.name, prizes_s.lang_path  
FROM prizes_i18n prizes_s WHERE prizes_s.lang_id = 637;
Martin Smith
You got there just before I did. I think most DBMS flavours have CONCAT()
APC
Thanks!!!!! it works!!
Oyeme
+1  A: 

Random guess...

prizes_s.translation_name + ' Copy' is too long for translation_name and you get string or binary data would be truncated error?

Is it SQL Server too? Is translation_name char or varchar?

gbn
+1  A: 

INSERT INTO prizes_i18n
(lang_id,translation_name,translation_desc,name,lang_path) SELECT prizes_s.lang_id , concat(prizes_s.translation_name,'copy') , prizes_s.translation_desc , prizes_s.name , prizes_s.lang_path
FROM prizes_s WHERE prizes_s.lang_id = 637;

Also I think, that in your FROM clause the table prizes_i18n is unnecessary.

tombom
There is only one table there `prizes_i18n`. It is aliased as `prizes_s`
Martin Smith
yes you are right!
Oyeme