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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restricting the number of records returned(COUNT)

Status
Not open for further replies.

texusgirl

Programmer
Aug 17, 2003
17
US
Hey everyone! Here is the problem...I am writing a stored procedure and need to restrict the number of returned records to 10 and can't seem to make it work. Here is the code:

Select
POH.PONumber,
POH.POEntryDate,
POH.DueDate,
POD.ItemCode,
POD.ItemDescription,
POD.UOMCode,
POD.DrawingNumber,
POD.ReceivedDate,
RH.ReceiverNumber,
RH.POTypeCode,
RH.VendorCode,
RD.CompanyCode,
RD.ReceiverNumber,
RD.OrderQuantity,
RD.UnitPrice

From [POHeaderHistory]POH
LEFT JOIN
[PODetailHistory]POD

ON
POH.PONumber = POD.PONumber AND
POH.CompanyCode = POD.CompanyCode
And POD.ItemCode = @ItemCode
LEFT JOIN

[ReceiverHeaderHistory]RH
ON

RH.ReceivedDate = POD.ReceivedDate AND
RH.CompanyCode = POH.CompanyCode AND
RH.VendorCode = POH.VendorCode And RH.POTypeCode = 'PO'


INNER JOIN

[ReceiverDetailHistory]RD

ON
RD.CompanyCode = POD.CompanyCode AND
RD.ReceiverNumber = RH.ReceiverNumber
AND RD.ItemCode = POD.ItemCode ORDER BY POD.RECEIVEDDATE
Any help will be greatly appreciated!
 
You can restrict the number of rows returned by using the TOP keyword. But, I am not sure if that's what you are wanting.
 
Sounds like that is what I am looking for...where do I put it though?
 
SELECT TOP 10

But you should have an ORDER BY statement so SQL Server knows what you want the TOP 10 of (for example:
ORDER BY mydate DESC
would return the 10 latest dates.

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top