Solved

limiting return values

Posted on 2005-04-26
2
175 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
ID: 13868924
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
ID: 13868950
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

816 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

8 Experts available now in Live!

Get 1:1 Help Now