Results 1 to 2 of 2
  1. #1
    davidman is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Aug 2013
    Posts
    2

    Require parameter value when running SQL

    Hi



    I have the query below, but whenever I try to run it Access wants me to enter a value for CurrentPoints, could someone have a look at my query please?

    I'm trying to show all employees who have less than 1.5 points, are 3P Onsite Workers and have been here for 8 weeks or more.

    Code:
    SELECT WFR.EmployeeID,
    WFR.EmployeeName,
    WFR.Supervisor,
    (SELECT SUM(Points)FROM Points WHERE Points.EmployeeID = WFR.EmployeeID GROUP BY Points.EmployeeId) AS CurrentPoints,
    WFR.RehireDate,
    WFR.EmployeeClass
    FROM WFR
    WHERE WFR.EmployeeID Not In (SELECT ID FROM Disciplinaries) AND WFR.EmployeeClass = '3P Onsite Worker' AND CurrentPoints < 1.5
    AND DATEDIFF(d, Now(),WFR.RehireDate) > 7 * 8;
    Click image for larger version. 

Name:	Relationships.JPG 
Views:	13 
Size:	63.2 KB 
ID:	13630

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    WHERE WFR.EmployeeID Not In (SELECT ID FROM Disciplinaries)
    I don't think this will give you the results you expect.
    This will result in a 1 to 1 relationship between WFR.EmployeeID and Disciplinaries.ID.
    Shouldn't it be
    Code:
    WHERE WFR.EmployeeID Not In (SELECT EmpID FROM Disciplinaries)

    As for the request for the parameter, you might create another query
    Code:
    SELECT EmpId, SUM(Points) AS CurrentPoints FROM Points GROUP BY Points.EmpId
    Name it "qryPoints"

    and join it with the your query.

    This is air code. I do not have Access available to test this , but you should get the idea....
    Code:
    SELECT WFR.EmployeeID,
    WFR.EmployeeName,
    WFR.Supervisor,
    WFR.RehireDate,
    WFR.EmployeeClass,
    qryPoints.CurrentPoints
    FROM WFR INNER JOIN qryPoints ON qryPoints.EmpID = WFR.EmployeeID    ' << not sure if this is correct syntax
    WHERE WFR.EmployeeID Not In (SELECT EmpID FROM Disciplinaries) 
    AND WFR.EmployeeClass = '3P Onsite Worker' 
    AND qryPoints.CurrentPoints < 1.5
    AND DATEDIFF(d, Date(),WFR.RehireDate) > 7 * 8;
    The blue is what I changed...

    Also, I changed Now() to Date(). Now() is date and time, Date() is the date only (actually the time is 00:00:00)


    My $0.02

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Running a Parameter Query
    By ELW in forum Queries
    Replies: 4
    Last Post: 05-09-2012, 08:06 PM
  2. Running Parameter Requires Table ID# Not Field Name
    By gabrielnerf in forum Queries
    Replies: 3
    Last Post: 02-05-2012, 12:34 AM
  3. Can queries require 4GB of ram?
    By chris@staples in forum Queries
    Replies: 3
    Last Post: 06-20-2011, 03:28 PM
  4. Running parameter queries from VBA
    By John Southern in forum Programming
    Replies: 6
    Last Post: 03-25-2010, 10:24 AM
  5. require help with query
    By ashiers in forum Queries
    Replies: 2
    Last Post: 04-15-2009, 08:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums