Computed column in SQL View

2019-08-05 16:52发布

问题:

My current view produces this kind of output...

Product1 Product2
Jet      Ski
Water    Polo

Could i use a computed column in a view, in order getting results like these?

Product1 Product2 Computed
Jet      Ski      Jet Ski
Water    Polo     Water Polo

回答1:

Sure:

select Product1, Product2, Product1 + ' ' + Product2 as [computed]
  from my_table


回答2:

Computed columns are defined at the table level, but why not simply concatenate?

SELECT 
    Product1, 
    Product2, 
    Product1 + ' ' + Product2 AS FullProductName 
FROM 
    MyProductTable