开发者

INSERT INTO SELECT,copy value+ 'string'

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'
        , pri开发者_C百科zes_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.


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;


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜