Results 1 to 2 of 2
  1. #1
    jdashm is offline Advanced Beginner
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2016
    Posts
    58

    Union Query Issure

    I am trying to create a union query that will combine data from 3 tables. They all use the same type of unique identifier (i.e. StudentID). I keep getting a "Data Type Mismatch in Criteria Expression" when I try to execute it. I have tried running each of the queries separately without issues as well as in pairs. I only get the error when I try to run all 3 together. I think I may have narrowed down the issue to one field (TRS_Scores) which happens to be a calculated field in its query. Here is the sql I have written...

    SELECT tblGateStatus_504_FR_CEDLT.[Student ID]
    , tblGateStatus_504_FR_CEDLT.[Last Name] as Last_Name
    , tblGateStatus_504_FR_CEDLT.[First Name] as First_Name
    , tblGateStatus_504_FR_CEDLT.FR_504_CELDT_Score


    , NULL as TRS_Scores
    , NULL as SBAC_Math
    , Null as SBAC_ELA
    FROM tblGateStatus_504_FR_CEDLT

    Union

    SELECT tblPowerSchoolData.[Student ID]
    , tblPowerSchoolData.[Last Name] as Last_Name
    , tblPowerSchoolData.[First Name] as First_Name
    , NULL as FR_504_CELDT_Score
    , tblTeacherScoringSheets.[Average Score] AS TRS_Scores
    , NULL as SBAC_Math
    , Null as SBAC_ELA
    FROM tblPowerSchoolData Right JOIN tblTeacherScoringSheets ON tblPowerSchoolData.[Student ID] = tblTeacherScoringSheets.[Student ID]

    UNION
    SELECT tblPowerSchoolData.[Student ID]
    , tblPowerSchoolData.[Last Name] as Last_Name
    , tblPowerSchoolData.[First Name] as First_Name
    , NULL as FR_504_CELDT_Score
    , NULL as TRS_Scores
    , tblSBACScores.[SBAC Math 2016] as SBAC_Math
    , tblSBACScores.[SBAC ELA 2016] as SBAC_ELA
    FROM tblPowerSchoolData INNER JOIN tblSBACScores ON tblPowerSchoolData.[Student ID] = tblSBACScores.[Student ID];


    Appreciate any help I can get.
    Thanks.

  2. #2
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    Pretty sure that the first select query in a UNION clause 'dictates' what follows, to put it one way. So while the 3 may run independently, the subsequent ones may not conform to the first when you try to meld them. I'd check if all the data types of the fields involved in the subsequent queries are the same. The error is telling you that one of these don't conform to the first set of data types. You are probably trying to put numbers and text into the same union field, for example.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Convert Union Query to non-union help
    By Ekhart in forum Queries
    Replies: 2
    Last Post: 01-10-2017, 03:39 AM
  2. help with Union Query
    By swenger in forum Queries
    Replies: 5
    Last Post: 08-31-2016, 10:47 AM
  3. Replies: 4
    Last Post: 12-20-2015, 02:35 PM
  4. Replies: 8
    Last Post: 10-22-2012, 07:43 PM
  5. Union Query Help
    By pmp in forum Queries
    Replies: 4
    Last Post: 10-28-2011, 06:41 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