SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Query to return specific number of rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vergy39
Starting Member

USA
9 Posts

Posted - 06/14/2012 :  16:34:01  Show Profile  Reply with Quote
I need to write a query that will return a specific number of rows by AssociateNumber. In some cases, an associate will have more then the required number and in some the associate will have less. currently, my query returns all records for all associates. I only want 10 records per associate if they have that many, and if they have less than 10, I want all of them. I tried the use Top 10 and RowCount, but failed. Any assistance is greatly appreciated. Below is what I currently have. I think I need to set up Cases, but a little confused.


"Select a.AssocID, b.tiCenter, b.NameFirst, b.NameLast, a.AcctDate, a.Division, a.AcctNum, a.Jcode, a.Credit
From csAudit.dbo.XSCM189 a
Left Join fwAIMS.dbo.tblAIMSProfile b On a.AssocID = b.AssociateNumber
Where JCode = 909 And AcctDate Between '2012-06-03' And '2012-06-09'
Group By a.AssocID, b.tiCenter, b.NameFirst, b.NameLast, a.AcctDate, a.Division, a.AcctNum, a.JCode, a.Credit
Order By a.AssocID"

Thanks
David

visakh16
Very Important crosS Applying yaK Herder

India
47099 Posts

Posted - 06/14/2012 :  17:07:36  Show Profile  Reply with Quote
can you show some sample data without which we cant see which table has which data

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Vergy39
Starting Member

USA
9 Posts

Posted - 06/14/2012 :  17:51:00  Show Profile  Reply with Quote
Thanks visakh16. I am new to this site so not sure if can paste attachements or not. Basically, we have a table that houses data regarding associates and the functions that they have performed. We want to audit a certain amount of these functions. This table is the XSCM189 table. This table only uses associate pin numbers, and we want to match them up with the associates name in the table called tbl.AIMSProfile. The xscm189 table lists the records by associate number. Hope this helps.

thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47099 Posts

Posted - 06/17/2012 :  12:38:31  Show Profile  Reply with Quote
just post data in below format

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000