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

后端 未结 4 1691
[愿得一人]
[愿得一人] 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条回答
  •  Happy的楠姐
    2021-02-18 14:32

    I think you're looking for the concat function here.

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

    This link will probably be helpful

    MySQL combine two columns into one column

提交回复
热议问题