Case when a value is different to other value, SQL Server

后端 未结 4 1673
[愿得一人]
[愿得一人] 2021-02-18 13:57

I have this table structure for table prices:

CREATE TABLE prices
(
     id int, 
     priceFrom int, 
     priceUp int
);

INSERT INTO prices (id,          


        
4条回答
  •  一整个雨季
    2021-02-18 14:36

    You have to CAST to VARCHAR:

    select pricefrom, priceup,
           case
              when pricefrom = 0 then null
              when priceFrom <> priceUp then concat(cast(priceFrom as varchar(8)),
                                                    ' - ', 
                                                    cast(priceUp as varchar(8)))
              when priceFrom = priceUp then cast(priceFrom as varchar(8))
           end as FinalPrice
    from prices
    

提交回复
热议问题