Hi all,
I have a product table which include following fields : Id,Status,Price,CreatedTime,LastModifyTime
When i create new product : Status Field in product table is "new"
When i update information product such as price : Status Field in product table is "updated"
My problem:
Product can not be always new status , I want to write query after 5 days status product will be set normal. When status product is updated , it can not set "normal".Mean that we have 3 status : "new","updated","normal"
How can i do that ?
Thank you very much ! Have a good day !
you can consider using a computed column for Status
Status as
case when datediff(day, CreatedTime, getdate()) <= 5
and LastModifyTime is null then 'new'
when LastModifyTime is null then 'normal'
else 'updated'
end
CREATE TABLE [dbo].[Product](
[Id] [int] NOT NULL,
[Status] AS
case when datediff(day, CreatedTime, getdate()) <= 5
and LastModifyTime is null then 'new'
when LastModifyTime is null then 'normal'
else 'updated'
end,
[Name] [nvarchar](50) NULL,
[Price] [real] NULL,
[CreatedTime] [datetime] NULL,
[LastModifyTime] [datetime] NULL,