473,386 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help Needed For Date field (Age) Calculation In SQl query

Hi experts,

I am working on SQL server 2005 reporting services and i am getting a
problem in writting a query.

Situation is given below.

There is one table in database Named Child

Now i have to find the All childrens whoes Age is 13 years Base on
Some given parameter.

If User select Augus 2007 then It has to calculate the Childs who born
in August 1994 And if he select September Then query

should show only those child Who born in September 1994 and so
on..... And use can select another year month also like

August 2009 ...
I am writting the following query

Select Child_Name, DOb from Child
where ((CONVERT(DateTime, A.Date_Of_Birth, 103) >= @ Parameter1
And (CONVERT(DateTime, A.Date_Of_Birth, 103) <= @Parameter2)

If i know already month and year then i can write easily parameter1
and parameter2 But since these are comming from user so i m not
finding how to handle this.
Now please suggest me what i have to write in Where statement I think
a lot but not getting any idea about it.

Any help wil be appriciated.

Regards
Dinesh

Aug 30 '07 #1
2 7246
If I understand correctly, you want to select on a specific month of
birth that is 13 years prior to a month provided as a starting point.

create table Born (Name varchar(20), dob datetime)

INSERT Born values('Nancy', '19940704')
INSERT Born values('Ralph', '19940804')
INSERT Born values('Edgar', '19940904')

declare @d datetime
set @d = '20070801'

SELECT @d, *
FROM Born
WHERE DATEDIFF(month,dob,@d) = (13 * 12)

DROP TABLE Born

Roy Harvey
Beacon Falls, CT

On Thu, 30 Aug 2007 03:18:34 -0700, Dinesh <di*******@gmail.com>
wrote:
>Hi experts,

I am working on SQL server 2005 reporting services and i am getting a
problem in writting a query.

Situation is given below.

There is one table in database Named Child

Now i have to find the All childrens whoes Age is 13 years Base on
Some given parameter.

If User select Augus 2007 then It has to calculate the Childs who born
in August 1994 And if he select September Then query

should show only those child Who born in September 1994 and so
on..... And use can select another year month also like

August 2009 ...
I am writting the following query

Select Child_Name, DOb from Child
where ((CONVERT(DateTime, A.Date_Of_Birth, 103) >= @ Parameter1
And (CONVERT(DateTime, A.Date_Of_Birth, 103) <= @Parameter2)

If i know already month and year then i can write easily parameter1
and parameter2 But since these are comming from user so i m not
finding how to handle this.
Now please suggest me what i have to write in Where statement I think
a lot but not getting any idea about it.

Any help wil be appriciated.

Regards
Dinesh
Aug 30 '07 #2
On Aug 30, 6:36 pm, Roy Harvey <roy_har...@snet.netwrote:
If I understand correctly, you want to select on a specific month of
birth that is 13 years prior to a month provided as a starting point.

create table Born (Name varchar(20), dob datetime)

INSERT Born values('Nancy', '19940704')
INSERT Born values('Ralph', '19940804')
INSERT Born values('Edgar', '19940904')

declare @d datetime
set @d = '20070801'

SELECT @d, *
FROM Born
WHERE DATEDIFF(month,dob,@d) = (13 * 12)

DROP TABLE Born

Roy Harvey
Beacon Falls, CT

On Thu, 30 Aug 2007 03:18:34 -0700, Dinesh <dinesh...@gmail.com>
wrote:
Hi experts,
I am working on SQL server 2005 reporting services and i am getting a
problem in writting a query.
Situation is given below.
There is one table in database Named Child
Now i have to find the All childrens whoes Age is 13 years Base on
Some given parameter.
If User select Augus 2007 then It has to calculate the Childs who born
in August 1994 And if he select September Then query
should show only those child Who born in September 1994 and so
on..... And use can select another year month also like
August 2009 ...
I am writting the following query
Select Child_Name, DOb from Child
where ((CONVERT(DateTime, A.Date_Of_Birth, 103) >= @ Parameter1
And (CONVERT(DateTime, A.Date_Of_Birth, 103) <= @Parameter2)
If i know already month and year then i can write easily parameter1
and parameter2 But since these are comming from user so i m not
finding how to handle this.
Now please suggest me what i have to write in Where statement I think
a lot but not getting any idea about it.
Any help wil be appriciated.
Regards
Dinesh- Hide quoted text -

- Show quoted text -
Thanks Roy Harvey
Yes for your reply. I got my solution with your help.
Regards
Dinesh

Aug 31 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michelle | last post by:
Hi all I am new to sql code and am not even sure i am posting this in the right place but would be grateful for any assistance. I am trying to write a sql query as follows: I want to select...
3
by: eamon | last post by:
Im making this stored procedure to return the age of the user to the web control but the problem is that DATEPART(). I can only Specify one and i need the age to to the exact format of mm dd yy but...
6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
4
by: Neil Grantham | last post by:
I am creating a database for Nursery children, and part of the reporting requirement, is to show those on the waiting list. Children will be elligible for entry by age, and so based on their...
0
by: leavandor | last post by:
I am trying to design a query that works with a relationship between a Table and a Query. I am comparing a value in the table with a computed value inside the query. The reason for this is that...
10
by: sandraz444 | last post by:
I have an expression in the query under my form to autofill the date under a certain condition but it wont write to the underlying table?? The date shows in the form but not the table. Does anyone...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
1
by: AR123 | last post by:
The mandatory form field that is not working is the TYPE OF ILLUSTRATION. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Proforma</title> <meta...
3
by: murch.alexander | last post by:
I made a simple public function to set and return a date value (see below). I have a number of queries that call up the function to get the "As Of Date," which is typically set to today's date....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.