0

EquipmentSQL Server 2008 に次のようなテーブルがあります。

CREATE TABLE [dbo].[Equipment](
[EquipmentID] [nchar](10) NOT NULL,
[EquipmentName] [nchar](50) NOT NULL,
[ProducedDate] [date] NOT NULL,
[WarrantyPeriod] [int] NOT NULL,
[SerialNumber] [nchar](20) NOT NULL,
[BrandID] [tinyint] NOT NULL,
CONSTRAINT [PK_Equipment] PRIMARY KEY CLUSTERED 
)

列およびに基づいて、計算時にまたはWarrantyStatusを返す計算列が必要です。UnexpiredExpiredProducedDateWarrantyPeriod

これは間違っていますが、それは私が欲しいものです:

ALTER TABLE [dbo].[Equipment]
ADD [WarrantyStatus] AS IIF(DATEDIFF(MONTH, [ProducedDate], GETDATE()) < [WarrantyPeriod], "Unexpired", "Expired")
4

1 に答える 1

2

試す:

ALTER TABLE [dbo].[Equipment]
ADD [WarrantyStatus] AS 
case when DATEDIFF(MONTH, [ProducedDate], GETDATE()) < [WarrantyPeriod]
then 'Unexpired'
else 'Expired'
end
于 2012-10-31T20:52:34.877 に答える