Query Syntax- Minimum 5% or 5 records depending on which is greater

INSERT INTO tblAuditResults ( LoadDate, [Order#], [Overall Score], BU, Employee, Name, SSN, [Position], [EE Grp Text], [Package Type], CalendarDay )
SELECT TOP 5 PERCENT tblOrder_Activity.Date_Added, tblOrder_Activity.[Order #], tblOrder_Activity.[Overall Score], tblOrder_Activity.BU, tblAuditPoolWeekly.Perner, tblOrder_Activity.Name, tblOrder_Activity.[SS#], tblAuditPoolWeekly.Position, tblAuditPoolWeekly.EmployeeText, tblOrder_Activity.[Package Type], tblAuditPoolWeekly.CalendarDay
FROM tblOrder_Activity INNER JOIN tblAuditPoolWeekly ON (tblOrder_Activity.[Overall Score] = tblAuditPoolWeekly.[Overall Score]) AND (tblOrder_Activity.[SS#] = tblAuditPoolWeekly.SSN)
GROUP BY tblOrder_Activity.Date_Added, tblOrder_Activity.[Order #], tblOrder_Activity.[Overall Score], tblOrder_Activity.BU, tblAuditPoolWeekly.Perner, tblOrder_Activity.Name, tblOrder_Activity.[SS#], tblAuditPoolWeekly.Position, tblAuditPoolWeekly.EmployeeText, tblOrder_Activity.[Package Type], tblAuditPoolWeekly.CalendarDay
HAVING (((tblOrder_Activity.[Overall Score])="Clear") AND ((tblOrder_Activity.BU)="Corp"));

Open in new window




I need to pull 5 records or 5% whichever is greater
kwarden13Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
Open a recordset using SELECT TOP 5 PERCENT ...
Count the records.

If count >= 5, run your insert query using TOP 5 PERCENT
If count < 5, run your insert query using TOP 5

/gustav
0
SharathData EngineerCommented:
Is this a similar to http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_26940853.html ?

Can you try changing the comparative operators?
INSERT INTO tblAuditResults 
           (LoadDate,[Order#],[Overall Score],BU,Employee,Name,SSN,[Position],[EE Grp Text],[Package Type],CalendarDay)
SELECT * 
  FROM (SELECT * 
          FROM QUERY_P5 
         WHERE 5 > (SELECT COUNT(* ) 
                       FROM QUERY_P5) 
        UNION ALL 
        SELECT * 
          FROM QUERY_T5 
         WHERE 5 <= (SELECT COUNT(* ) 
                      FROM QUERY_P5)) AS t1;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.