1

I run this SQL code and it displays me, result = 60 I did not understand why it returns me the sum of the variables while the @Result variable contains strings

SET @data_code = 10;
set @env_code = 20;
set @Id = 30;

set @Result = @data_code + '-' + @env_code + '-FrontEnd' + @Id;
select @Result
lilouzi
  • 71
  • 5
  • 2
    The `+` operator is implicitely casting the string to a number and ignoring anything that is not a number. – Stu Nov 01 '21 at 21:11
  • 1
    MySQL uses the `CONCAT()` function to concatenate strings, not `+`. – Barmar Nov 01 '21 at 21:15

1 Answers1

1

Use CONCAT()

SET @data_code = 10;
set @env_code = 20;
set @Id = 30;

set @Result = CONCAT(@data_code,'-',@env_code,'-FrontEnd',@Id);
select @Result

http://sqlfiddle.com/#!9/9eecb/251906

Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116