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.
Author |
Topic |
ann
Posting Yak Master
220 Posts |
Posted - 2007-04-23 : 10:18:37
|
I have to create a query whereby I need to extract info if the year of a date field(TerminateYear) is not <= than a parameter year or if it's null.Example:@year = 2007ID, TerminateYear1, Null2, 12/15/20063, 1/20/20054, 2/10/2008Results:1, Null4, 2/10/2008Hope this is enough information --- thanks |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-23 : 10:21:41
|
[code]Select *from TableWhere (Year(TerminateYear) > @year or TerminateYear IS NULL)[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-23 : 10:23:03
|
[code]select ID, TerminateYearfrom yourtablewhere TerminateYear >= dateadd(year, @year - 1900 + 1, 0)[/code] KH |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-23 : 10:23:53
|
Harsh-bot beat me to it  KH |
 |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-23 : 10:25:43
|
quote: Originally posted by khtan
select ID, TerminateYearfrom yourtablewhere TerminateYear >= dateadd(year, @year - 1900 + 1, 0) KH
Much better performance-wise! Excellent KH...Nice to know something new from you, always !Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-04-23 : 14:05:39
|
quote: Originally posted by khtan
select ID, TerminateYearfrom yourtablewhere TerminateYear >= dateadd(year, @year - 1900 + 1, 0) or TerminateYear IS NULL KH
Sorry KH, I just didn't want the original poster to think that was the complete solution. But, kudos for being for efficient. :) |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-04-23 : 17:55:23
|
Thanks Lamprey. I missed that. KH |
 |
|
|
|
|
|
|