Results 1 to 3 of 3

Thread: Adding formula to union query
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Dec 2017
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Adding formula to union query

    Hi everyone. I am almost done with my project, but I need help with something. Can someone help with getting the following to work?

    SELECT ID as Eval, "Preparation and Punctuality" AS Criteria, I_Q1 AS Grade, =IF([I_Q1]=1,"F","ERROR") AS LETTER_GRADE
    FROM issues
    UNION SELECT ID, "Subject Knowledge",I_Q2
    FROM issues
    UNION SELECT ID, "Available to Meet Student Needs",I_Q3
    FROM issues;

    I have done union queries numerous times before, however I have never tried to incorporate an if statement into one. I would like a formula that can translate number values into letters (1=F, 2=D, 3=C....) into a column. is this possible? Any help is appreciated.

    Thanks in advance!

  2. #2
    MrExcel MVP
    Moderator
    xenou's Avatar
    Join Date
    Mar 2007
    Location
    Clev. OH, USA
    Posts
    16,467
    Post Thanks / Like
    Mentioned
    11 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Adding formula to union query

    A union query MUST have the same number of columns in each part. So your query looks like it won't work (first part has 3 columns, and the other two have only two columns.

    At minimum you'd have provide some third values in the last two parts (an empty string, a dummy value such as "n/a", or a Null).

    Using: Office 2010/Win7 (work) Office 2010/Win7 (home)

    You are rich in proportion to the number of things you can let alone.
    -- Henry David Thoreau

  3. #3
    New Member
    Join Date
    Dec 2017
    Posts
    11
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Adding formula to union query

    Thank xenou. I see now that I do not have the 3rd column on the other parts now. Thanks for bringing that up. The last item appeared to be using "IF" instead of "IIF". Formula seems to work now. Thanks!
    Last edited by asmith601; Dec 7th, 2018 at 11:49 AM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •