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

后端 未结 10 2010
借酒劲吻你
借酒劲吻你 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 04:12

    Try casting the ints to varchar, before adding them to a string:

    SET @ActualWeightDIMS = cast(@Actual_Dims_Lenght as varchar(8)) + 
       'x' + cast(@Actual_Dims_Width as varchar(8)) + 
       'x' + cast(@Actual_Dims_Height as varhcar(8))
    
    0 讨论(0)
  • 2020-11-30 04:14

    Cast the integers to varchar first!

    0 讨论(0)
  • 2020-11-30 04:15

    There are chances that you might end up with Scientific Number when you convert Integer to Str... safer way is

    SET @ActualWeightDIMS = STR(@Actual_Dims_Width); OR Select STR(@Actual_Dims_Width) + str(@Actual_Dims_Width)

    0 讨论(0)
  • 2020-11-30 04:18

    I was tried the below query it's works for me exactly

     with cte as(
    
       select ROW_NUMBER() over (order by repairid) as'RN', [RepairProductId] from [Ws_RepairList]
      )
      update CTE set [RepairProductId]= ISNULL([RepairProductId]+convert(nvarchar(10),RN),0) from cte
    
    0 讨论(0)
提交回复
热议问题