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
 SQL Server Development (2000)
 select only rows by changing date help

Author  Topic 

hueby
Posting Yak Master

127 Posts

Posted - 2005-01-18 : 15:52:32
Hi all, I need some help figuring out this problem.

I have a table that has DateTime field. I want to include in my basic query some code that will pull the "previous" inputted rows by the last Date. There will be multiple rows too. Soo.. there would be say... 5 rows with a 1/12/05 date then 7 rows with a 1/11/05 date, and so on. How in the world can I just get those 5 rows with the 1/12/05 date WITHOUT having the user input a Date parameter????

X002548
Not Just a Number

15586 Posts

Posted - 2005-01-18 : 16:24:50
I don't get it...you want the last date? What about tomorrow?

"Tomorow may come.....it usually does"*

* JB



Brett

8-)
Go to Top of Page

hueby
Posting Yak Master

127 Posts

Posted - 2005-01-18 : 16:31:14
Yah, I just want the group of rows with the latest Date. BUT without having the user enter a date parameter. So the query would figure out the latest entered Date, and pull all the rows (which would be changing) with that Date. That make any more sense? :/
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2005-01-18 : 17:03:33
Post some sample data and expected results please.
I'm thinking you are looking for something with some DATEADD() magic in it.

Lookup DateAdd() in Books On-line.

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-18 : 17:04:11
SELECT *
FROM Event
WHERE TimeDate >= CONVERT(varchar(20), (SELECT MAX(TimeDate) FROM Event), 101)

Tara
Go to Top of Page

hueby
Posting Yak Master

127 Posts

Posted - 2005-01-18 : 17:09:55
Tara - THANK YOU. That is exactly what I was wanting... :D
Go to Top of Page

hueby
Posting Yak Master

127 Posts

Posted - 2005-01-18 : 17:28:30
Well.. if I wanna take this one step further and add a "purchase order" parameter in there as well...


SELECT TOP 100 PERCENT Purchord, ehours, eqty, eEquipNo, edate
FROM equip_used
WHERE eDate >= CONVERT(varchar(20), (SELECT MAX(eDate) FROM Equip_used), 101) AND purchord = '3517'
ORDER BY eEquipNo


Now.. obviously, if a P.O.# has a closer date than the one in the parameter it will show up with no results.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-01-18 : 17:34:59
You'll need to add that extra condition to the subquery as well.

Tara
Go to Top of Page

hueby
Posting Yak Master

127 Posts

Posted - 2005-01-18 : 17:51:50
Got it. thanks
Go to Top of Page
   

- Advertisement -