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
 General SQL Server Forums
 New to SQL Server Programming
 Is there a better way?

Author  Topic 

DavidChel
Constraint Violating Yak Guru

474 Posts

Posted - 2008-04-22 : 15:13:45
I'm trying to find the current period (fnnumber) that we are in. fdstart is the start of the periods.

select fnnumber from glrule where
fdstart=
(
select max(fdstart) from glrule
WHERE fdstart < getdate())

Is there a better way to do this?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-04-22 : 16:22:40
maybe:
select top 1 fnnumber
from glrule
order by fdstart desc


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-04-22 : 17:09:31
Paleozoic?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-04-23 : 05:07:23
Quaternary or Anthropocene, I'd say.

Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-04-23 : 05:17:32
You might need to add a where clause to spirit1's suggestion...

select top 1 fnnumber from glrule where fdstart < getdate() order by fdstart desc
And if fdstart is not necessarily unique, you might want a 'with ties' after the 'top 1'.


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

DavidChel
Constraint Violating Yak Guru

474 Posts

Posted - 2008-04-23 : 09:09:16
quote:
Originally posted by RyanRandall

You might need to add a where clause to spirit1's suggestion...

select top 1 fnnumber from glrule where fdstart < getdate() order by fdstart desc
And if fdstart is not necessarily unique, you might want a 'with ties' after the 'top 1'.


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.



Thanks for your help. That works and I'll use it.
Go to Top of Page
   

- Advertisement -