?
Solved

limiting return values

Posted on 2005-04-26
2
Medium Priority
?
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 28

Accepted Solution

by:
rafrancisco earned 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

777 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