Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last Work Order Used for Each Rate

Status
Not open for further replies.

dleewms

Programmer
Aug 19, 2001
118
US
I am using SQL Server 2005. I am attempting to find the last work order that was used for each rate category. I can find the date last used for a specific rate category, but am not able to get the ONE work_no associated with that date. The code below is still yielding multiple work orders for each category. Can anyone point me in the right direction? Thanks!

SELECT TOP (100) PERCENT dbo.rate_cat.rate_cat,
dbo.rate_cat.description,
max(dbo.[work].create_time) AS LastUseDate,
q.work_no
FROM dbo.[work]
LEFT OUTER JOIN dbo.rate_cat
ON dbo.[work].rate_cat = dbo.rate_cat.rate_cat
LEFT OUTER JOIN dbo.business
ON dbo.[work].bill_to_business_id = dbo.business.business_id
LEFT OUTER JOIN
(Select max(work_no) as work_no, create_time
From dbo.[work]
Group by create_time)q
ON work.create_time = q.create_time
and work.work_no = q.work_no
Group by dbo.rate_cat.rate_cat, dbo.rate_cat.description, q.work_no
ORDER BY dbo.rate_cat.rate_cat
 
Can you show some sample data and expected results?

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Sure. Sorry about that.

Work_No Rate_Cat Description Create_time

2359 10001 Platinum 2011-06-01
2364 10001 Platinum 2011-06-05
2375 10002 Diamond 2011-06-07
2378 10003 Gold 2011-06-08
2383 10002 Diamond 2011-06-10

I would like to see
10001 Platinum 2011-06-05 2364
10002 Diamond 2011-06-10 2383
10003 Gold 2011-06-08 2378
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top