Default column value using default or formula properties

I have a date column on my table defined as datetime (call_date) (not necessarily current date)

I also have 2 columns named  call_month and call_year ( both defined as varchar).

I would like the call_month and call_year values to be defaulted to month and year portions of call_date respectively.

Is it possible to do this using the default or formula values for the field definitions?


For example if call_date is 5/24/06....call_month would default to 5 and call_year would default to 06


I know I could do this using a trigger but just curious....
johnnyg123Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
NetminderConnect With a Mentor Commented:
Closed, 500 points refunded.
Netminder
Site Admin
0
 
raopsnCommented:
Yes you can use a trigger to that,
but why you want to store that data ? when you can derive it at any time
0
 
johnnyg123Author Commented:
I needed it to make it easier to do reporting .....actually...I figured it out


for call_month

(case when ([FOTCCallDate] is not null) then (datepart(month,[FOTCCallDate])) else '' end)


for call_year

(case when ([FOTCCallDate] is not null) then (datepart(year,[FOTCCallDate])) else '' end)


How can I close this case?
0
 
raopsnCommented:
0
All Courses

From novice to tech pro — start learning today.