How to concatenate in SQL Server

前端 未结 3 669
庸人自扰
庸人自扰 2021-01-28 01:34

My database doesn\'t have a specific column so I created a column in my query by switch. What I need is to concatenate this column with another column in the database:



        
3条回答
  •  鱼传尺愫
    2021-01-28 01:48

    You just need to try + operator or CONCAT function

    1. + for all SQL Server versions

      DurationType = ' + 'some text'
      
    2. CONCAT for SQL Server 2012 +

      CONCAT('DurationType = ', 'some text')
      

    Your query should be something like this

    SELECT certificateDuration
           ,'DurationType = ' + 
           CASE certificateDurationType
               WHEN 0 THEN 'Day'
               WHEN 1 THEN 'Month'
               WHEN 2 THEN 'Year'
           END
    FROM Scientific_Certification
    

提交回复
热议问题