Tuesday, April 04, 2006

Formula in SQL server 2000 database

Question:
How to use the formula when creating the table. What is the benefit of using this?

Gabbar:
CREATE table #mytable (myID int, PromoCode varchar(32),
PromoExpiration AS CASE WHEN PromoCode IS NOT NULL THEN dateadd(day,10,getdate()) ELSE NULL END)

Benifit is you don't have to take care of the value in this field in case of INSERT and UPDATE both. The value in the formula field are always in sync with your data.

No comments: