Link to home
Start Free TrialLog in
Avatar of johnnyg123
johnnyg123Flag for United States of America

asked on

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....
Avatar of raopsn
raopsn

Yes you can use a trigger to that,
but why you want to store that data ? when you can derive it at any time
Avatar of johnnyg123

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial