When you CREATE TABLE
using CASE
expression to create a computed column, you do not explicitly define the data type of this column:
CREATE TABLE OrderDetail
( OrderID INT
, ProductID INT
, Qty INT
, OrderDate DATETIME
, ShipDate DATETIME
, STATUS AS CASE
WHEN shipdate is NULL AND orderdate < DATEADD( dd, -7, GETDATE()) THEN 3
WHEN shipdate is NOT NULL THEN 2
ELSE 1
end
)
GO
How SQL Server decides the data type of this column?