How to Concatenate Numbers and Strings to Format Numbers in T-SQL?

A couple of quick notes:

  • It’s “length” not “lenght”
  • Table aliases in your query would probably make it a lot more readable

Now onto the problem…

You need to explicitly convert your parameters to VARCHAR before trying to concatenate them. When SQL Server sees @my_int + ‘X’ it thinks you’re trying to add the number “X” to @my_int and it can’t do that. Instead try:

SET @ActualWeightDIMS =
     CAST(@Actual_Dims_Lenght AS VARCHAR(16)) + 'x' +
     CAST(@Actual_Dims_Width  AS VARCHAR(16)) + 'x' +
     CAST(@Actual_Dims_Height  AS VARCHAR(16))

Leave a Comment