Trigger To Calculate Age From Date Of Birth

Here's the problem. I want to insert age in years to a table of children, using a MS SQL trigger to calculate age from Date of Birth (DOB). DOB format is mm/dd/yyyy. The DOB input comes from an ASP Insert statement. I've tried to use DateDiff and a user-defined function to calculate age without any success. Also the trigger needs to account for children of less than 1 year old, could be a 0. Age is integer in the children table. Any help is greatly appreciated. The sooner the better. Even a kick start is better than nothing.

View Replies


How To Get Age From Date Of Birth

Hello Everyone,

I have a table containing a column "date of Birth" in char datatype, I need to calculate Age for the person from his or her date of birth. how would I be able to do that?

Any help will be appreciated.


View Replies View Related

Selecting Date Of Birth

I have table with column Date Of Birth its datatype is smalldatetime. Now I was looking for SQL Statement like I will give from date and to date as parameter it should select date of birth occurring between that date and month.

View Replies View Related

Average Date Of Birth

Hi, folks.
I have a table with a column Date_of_birth.
I want to evaluate average date_of_birth by grouping on depts.
AVG function doesn't seem to work with datetime col. Plz help.

View Replies View Related

Birth Date 1900-01-01 00:00:00.000


How to check the default value set up for datetime field? The reason I am asking is my database

field "birthday" is datetime(8), the default value I set to '' already. Everytime my asp program
have empty birthday or invalid birthdate for this field, the system automaticaly set it to

1900-01-01 00:00:00.000

Do you know what happened?


View Replies View Related

Date Of Birth Conversion

Can someone help please?
I'm using SQL Server 7 and trying to update a table containing over 250,000 records. I have a character(8) (CHARDOB) field representing dates of birth in the form YYYYMMDD and would like to update my datetime field (DOB) using a simple update command like:-

5, 2) + '/' + LEFT(CHARDOB, 4)

but get the message:-

Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.

The strange thing is that this works on a small dataset but crashes and burns on larger ones. I have tried different CAST and CONVERT options to transform the data into the correct format. I have tried a stored procedure, DTS transformations and execute SQL task in my DTS package without success.

Any help will be appreciated.

View Replies View Related

How To Get Date Of Birth And Age In Years?

I have a table name employee and datetime column named dateofbirth, how can i write a select statement to show their, date of birth and age in years?

This is how i did it, i couldn't finish it, Any feedback would be very thankful.

select name, datebirth, year(dateofbirth)
from employee

View Replies View Related

Get Date Of Birth Query Problem...

i want to make one SQL Query in that i have problem so please help me
i have three column  ID,Name,DOB
in that i want top 5 name whose Birthday is incomming   days....
reply as soon as..

View Replies View Related

Formatting For A Birth Date Field??

Hello, I'm new to SQL Server, working for a non-profit computerizing alot of its data.I imported a table of people's names, birth dates, etc. into SS2005from Access, and the birth_date was imported as an Access date/timefield, giving it the datetime datatype in SQL.The column values look like:10/14/1964 12:00:00 AMWhere and how do I learn to specify that all fields like this should bein ISO format of yyyy-mm-dd??Do I have to create a new column and put all the dates into it??Should I just convert the data in queries/views??Use a constraint to format the data??I can redo the Access table if necessary, it is only 300-some rows.I tried BOL but it was not helpful...The end users will likely enter mm/dd/yy or mm/dd/yyyy and it will haveto be stored properly in the database table as column/fieldbirth_date...Thank you, Tom

View Replies View Related

Creating Birth Date From Day, Month, Year Fields

I have 3 fields (DOB_YEAR, DOB_MO, DOB_DAY)

They are populated like this (1985, 12, 21)

I would like to take the 3 values of populate one field (BIRTH_DATE) with these combined values to look like this (19851221) BIRTH_DATE is an 8 character field in datetime format.

The code

SET BIRTH_DATE = (dob_year+dob_mo+dob_day)

Returns 6/11/1905 for 1959,11,17

View Replies View Related

How To Calculate Cost Of A Trigger?

I wanna used derived fields to improve select performance of my system.
How can I  calculate the trigger cost in the system?

View Replies View Related

A Trigger To Calculate A Due Time

Hi i am trying to make a trigger that calculates a new due time from a start time. I have a hour target like 24 hours, but the dates have an starttime and stoptime or the days could even be closed. I need it to calculate the new due datetime using the 24 hours as effective working time.

Any ideas ?

View Replies View Related

Calculate Maximum Value Of Childrecords In A Trigger?

I have a parent record en some child records.

Let's say the child records have a field with a value in the range 1-9

Now I want to find the maximum value in the child records.

When I have that value, I want to write this value in a field in the parent record.

1) Should I do this in a (update) trigger?

2) How do you write such a trigger in sql-express?

thanks Klaas


View Replies View Related

Calculate Date

Hi All!
I need a query to find all dates from today to one-year back.
If I start from today day I need find all dates until 11/12/98.
Thanks a lot.

View Replies View Related

Calculate Week From Date


I want to convert a date to a weeknumber in my view.
How is this possible with SQL?

View Replies View Related

Calculate Weekending Date.

Can someone help me with this. I need to calculate the week endingdate of the first week of the year based upon a year provided by theuser. Is there a simpler way other than writing my own UDF?

View Replies View Related

Calculate Date Column


I'm using MS SQL Server 7--

I have a meter cycle table called tblMeterCycle. It shows a schedule of customer meter read dates. How can I show all the customers that have a meter read date due; that is; when the MeterReadDate column = Now() date; or the MeterReadDate column is one day less, or one day more than the Now() date? The MeterReadDate column format is mm/dd/yy.

Any suggestions?

View Replies View Related

Calculate Workdays From A Date

This is one way you can add a number of workdays to a specific date and return a workday (monday-friday).CREATE FUNCTION [dbo].[fnAddWorkdays]
@StartDate DATETIME,
@DaysToAdd INT
+ @DaysToAdd / 5 * 7
+ @DaysToAdd % 5
+ CASE WHEN (@@DATEFIRST + (DATEPART(WEEKDAY, @StartDate + CASE (@@DATEFIRST + (DATEPART(WEEKDAY, @StartDate) - 2)) % 7 WHEN 5 THEN 2 WHEN 6 THEN 1 ELSE 0 END) - 2)) % 7 + @DaysToAdd % 5 > 4

E 12°55'05.25"
N 56°04'39.16"

View Replies View Related

Calculate Date Field

I want to get the number of days pending for a perticular column. I want the out put as a integer value.

This is what I used for my calculated field.
But when i write this day is underlined in red. It says unrecognized identifier.

=DATEDIFF(Day, GETDATE(),Fields!SubmittedDate.Value)

If I use "day", then it is not underlined but still it does not work.

When I use following query, I get no error message. but still no data in the column too.

=DATEDIFF("d", Fields!SubmittedDate.Value, "GETDATE()" )

Can anyone tell me why is that?


View Replies View Related

How To Calculate A Date Difference In Days

Suppose I have these two days fields
ddold 1/1/2005 12:00:00 AM
ddnew 2/1/2007 12:00:00 AM

How can i get the DateDifference of these two dates in days.

View Replies View Related

Calculate Quarterly Dates From A Start Date

What is the correct way to calculate the next quarterly dates form a given start date

dateadd("q", 1 , StartDate)

using the above it calculates what month the next quarter is in but not the actual date

if my startdate 15/01/2005 (<= dd/mm/yyyy british date)

i would like to calculate the next quartly date from the 15th of jan

would i have to used days 365 then / by 4 to split the year into 4 then use that result to just add days to the startdate to get the next date ?

i.e. quarter (1 year) = 91.25 days

View Replies View Related

How To Calculate Expiry Date Using Stored Procedure

Hi, i'm trying to calculate on the expiry date for product which include the start date and end date.

the product can't b displayed if the start date haven't reached the date, besides, it oso can't b displayed if it has expired.

the storedprocedure tat i've written is:

DateDiff(day, StartDate, getDate())<=0
DateDiff(day, EndDate, getDate())>=0

i wonder why it can's show the result!!! is the code correct?

View Replies View Related

How To Calculate The Total Days Between Open And Close Date

Hi All,
I have a table call case and case_status have two fields, date and status as below:
date                          status
04/01/2006               open
04/05/2006               closed
04/10/2006               open
04/15/2006               closed
Whenever i open and closed the case, one record is insert into the case_status table.
Now I would need to calculate the total days of the case in storeprocedure.
Anyone can help me please.

View Replies View Related

Calculate Number Of Working Days Back From A Date

I need to calculate the number of working days from a date backwards. For example 2 working days before Thursday would be the Tuesday (as a basic example)

I use the following code and a Calendar table to calculate the working days from a date but can anyone help with reworking this query to do the reverse

declare @WorkingDate as datetime

SELECT @WorkingDate=dt
FROM tblCalendar AS c
WHERE (@WorkingDays =
FROM tblCalendar AS c2
WHERE (dt >= @StartDate) AND (dt <= c.dt) AND (IsWeekday = 1) AND (IsHoliday = 0))) AND (IsWeekday = 1)
AND (IsHoliday = 0)

-- Return the result of the function
RETURN convert(varchar(12),@WorkingDate,106)

Hope someone can help


View Replies View Related

T-SQL Scritp To Calculate The Last 6 Months Of Data In A Date Field.

Hi there,

if any body out there has done this before, can you please post the T-SQL script that calculate whatever last months of data based on a Date field.

Thanks very much,


View Replies View Related

System Date In Trigger

What is the script to insert system date in a table at insertion time using trigger.

View Replies View Related

[ask] How To Run A Trigger Or Store Precedure In Certain Date?

hello, i have a database that will be updated on a certain datei have a column "UPDATE_DATE" which specifies the updating date, my question is"how should i make the trigger or stored procedure runs only on the date that has been specified"thanks for the assistance 

View Replies View Related

How To Get A Custom Trigger To Fire On A Certain Date

I am using SQL Server 2005 database for a webbased application built on .net 2.0. Here is my situation. I have a SubmitDate and a Status field in a table. I want the trigger to fire based on the datevalue in the SubmitDate field. SubmitDate field is the last date for the user to submit an application. For eg: if the SubmitDate value is 03/10/07 , I want the trigger to fire on :01 of 03/11/07 to change the Status field value to Inactive. Is that possible? Thoughts on how to do it?

View Replies View Related

Date Driven Email Trigger?

Hello to a new forum. I am very impressed with the level of ability I have been seeing on this forum and all the helpful posts that are going on.

I am hoping someone can help me solve my problem. I know enough SQL to be very dangerous how to create, delete, insert, update etc... and how to build queries. Here is my dilemma I need to have a piece of scheduling software send out reminder emails based on a DATETIME field. I am running SQL Server 2005, and the database mail is already configured and can successfully send out email from the management studio interface.

Does anyone know of a tutorial or can point me in the right direction to accomplish this task. I am well versed in PHP, and am hoping I might be able to get the server to trigger a PHP script or something to this extent.

View Replies View Related

Copyrights 2005-15, All rights reserved