I need to save an amount of time (3 days, 1 month, 5 years, etc).
Datetime seems to be for saving a date and time (4/5/14 21:03). I could save the number of days as a number, but I will like to be able to save in different units (days, weeks, months...)
Is there any way of doing it?
SQL Dynamic DatePart when using DateDiff
Basically, you need to store datepart and number to apply
DATEADD (datepart , number , date)to a date. Splitting one string on each value might be too resource-consuming, so it might be best to use two separate fields:char(1)for datepart andsmallint(-32,768 to 32,767 should be enough) for number to save on storage space.Without user functions and Dynamic SQL support in SQL Server Compact the only option to implement the logic seems to be through the
CASEstatement: