Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Need help in Query

Author  Topic 

shakilhyd
Starting Member

16 Posts

Posted - 2008-08-03 : 01:44:15
Hi,
I am getting current year in the WHERE clause condition in the following script but I want to get year 2006 not 2007. How can I update the script so that I can get year 2006 instead of 2007.

I need require editing in the following line of script
(CONVERT(NUMERIC, DATEDIFF(YEAR, m.dob, GETDATE()), 101) / 5 = DATEDIFF(YEAR, m.dob, GETDATE()) / 5)
Can you please help in this regard.



Select * from member m

WHERE (m.clientid = 16) AND (w.benelig = 1) AND
(CONVERT(NUMERIC, DATEDIFF(YEAR, m.dob, GETDATE()), 101) / 5 = DATEDIFF(YEAR, m.dob, GETDATE()) / 5)


Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-03 : 13:39:21
Didnt understand where you're getting year part. what you're doing here is returning number of years passed from dob to today. if your question was to compare to 2006 instead of today use this.

(CONVERT(NUMERIC, DATEDIFF(YEAR, m.dob, DATEADD(yy,DATEDIFF(yy,0,GETDATE())-3,0)), 101) / 5 = DATEDIFF(YEAR, m.dob, DATEADD(yy,DATEDIFF(yy,0,GETDATE())-3,0)) / 5)
Go to Top of Page

shakilhyd
Starting Member

16 Posts

Posted - 2008-08-03 : 16:00:42
Hi,
Its wrong. I wanted to get year-2006 not 2008. In the following query I am getting year 2008 because I am using getdate() but I wanted to get year-2006 instead of 2008. How can I get. Please advise. Thanks.

quote:
Originally posted by shakilhyd

Hi,
I am getting current year in the WHERE clause condition in the following script but I want to get year 2006 not 2007. How can I update the script so that I can get year 2006 instead of 2007.

I need require editing in the following line of script
(CONVERT(NUMERIC, DATEDIFF(YEAR, m.dob, GETDATE()), 101) / 5 = DATEDIFF(YEAR, m.dob, GETDATE()) / 5)
Can you please help in this regard.



Select * from member m

WHERE (m.clientid = 16) AND (w.benelig = 1) AND
(CONVERT(NUMERIC, DATEDIFF(YEAR, m.dob, GETDATE()), 101) / 5 = DATEDIFF(YEAR, m.dob, GETDATE()) / 5)


Thanks.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-03 : 16:01:56
Then substract off 2 years using DATEADD.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

shakilhyd
Starting Member

16 Posts

Posted - 2008-08-03 : 23:00:59
Hi,
What will be updated script. Can you please update script.

Thanks.

quote:
Originally posted by tkizer

Then substract off 2 years using DATEADD.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-03 : 23:59:08
answered at http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3699966&SiteID=1

SELECT  * 
FROM Curben C
WHERE m.optcode = 'Y'
AND m.dob >= DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) - 2, 0) -- more AND equal to 2 years ago 1st of Jan : 2006-01-01
AND m.dob < DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) - 1, 0) -- less than 1 YEAR 1st of Jan : 2007-01-01



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -