Solved

Default column value using default or formula properties

Posted on 2006-06-12
5
496 Views
Last Modified: 2010-05-18
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....
0
Comment
Question by:johnnyg123
  • 2
5 Comments
 
LVL 9

Expert Comment

by:raopsn
ID: 16889728
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
 

Author Comment

by:johnnyg123
ID: 16889830
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
 
LVL 9

Expert Comment

by:raopsn
ID: 16889856
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 16932443
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now