Search code examples
sqlsql-serverstored-proceduresstring-concatenation

How to update a table concatenating the strings in two columns?


I want to update a column setting it up as the concatenation of the string in one column + the file extension (in this case, '.AVI').

I tried the following but it affects 0 rows; I know for a fact that there are records which have a 'FALSE' value for Video_Name.

Any ideas what I'm doing wrong? Thanks!

declare @creativity varchar
update [UK_Telco_Pressure_2018Q3_2019-02-26 W6] 
set Video_Name=concat(@creativity,'.AVI') where Video_Name = 'false' and
@creativity=Creativity

Solution

  • I would expect something like this:

    declare @creativity varchar(255);  -- length is really important
    
    set @creativity = <some value goes here> ;  -- value is really important
    
    update [UK_Telco_Pressure_2018Q3_2019-02-26 W6] 
        set Video_Name = concat(@creativity, '.AVI')
        where Video_Name = 'false' and
              Creativity =  @creativity;
    

    Or perhaps you just want:

    update [UK_Telco_Pressure_2018Q3_2019-02-26 W6] 
        set Video_Name = concat(creativity, '.AVI')
        where Video_Name = 'false' ;