Solved

limiting return values

Posted on 2005-04-26
2
173 Views
Last Modified: 2010-03-19
I need to bring back the first of N entries in a table with multiple records of the same account number. There is a mdate in the table and I want the data associated with the latested mdate.

Thanks,
Rut
0
Comment
Question by:rutledgj
2 Comments
 
LVL 28

Accepted Solution

by:
rafrancisco earned 100 total points
Comment Utility
Try this:

SELECT *
FROM YourTable A
WHERE MDATE = (SELECT MAX(MDATE) FROM YourTable B
                           WHERE A.AccountNo = B.AccountNo)
0
 
LVL 34

Expert Comment

by:Brian Crowe
Comment Utility
Not sure if this is what you're looking for...

CREATE PROCEDURE myProc
     @AccountNumber int,
     @mdate datetime,
     @Rows int
AS

SET ROWCOUNT @Rows

SELECT ... FROM myTable WHERE AccountNumber = @AccountNumber AND mdate = @mdate

SET ROWCOUNT 0
GO

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now