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

后端 未结 10 2052
借酒劲吻你
借酒劲吻你 2020-11-30 03:45

I have the following function

ALTER FUNCTION [dbo].[ActualWeightDIMS]
(
    -- Add the parameters for the function here
    @ActualWeight int,
    @Actual_D         


        
10条回答
  •  一个人的身影
    2020-11-30 03:57

    Change this:

    SET @ActualWeightDIMS= @Actual_Dims_Lenght + 'x' + 
        @Actual_Dims_Width + 'x' + @Actual_Dims_Height;
    

    To this:

    SET @ActualWeightDIMS= CAST(@Actual_Dims_Lenght as varchar(3)) + 'x' + 
        CAST(@Actual_Dims_Width as varchar(3)) + 'x' + 
        CAST(@Actual_Dims_Height as varchar(3));
    

    Change this:

    SET @ActualWeightDIMS = @ActualWeight;
    

    To this:

    SET @ActualWeightDIMS = CAST(@ActualWeight as varchar(50));
    

    You need to use CAST. Learn all about CAST and CONVERT here, because data types are important!

提交回复
热议问题