Incorrect syntax near the keyword 'UNION'. "


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Incorrect syntax near the keyword 'UNION'. "

  1. #1
    Join Date
    Aug 2007
    Posts
    30

    Incorrect syntax near the keyword 'UNION'. "

    HI,,
    Please help me resolve this error.."All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists."
    query:
    Code:
    sql = "SELECT EVENT_ID,EVENT_DATE,COMMENT FROM EVENTS WHERE CALL_ID=" & CallId & " UNION ALL SELECT A.USER_NAME from USERS A INNER JOIN EVENTS B ON A.USER_ID=B.USER_ID WHERE B.CALL_ID=" & CallId & ""
    And am getting this error for the following query."Incorrect syntax near the keyword 'UNION'. "
    query:
    Code:
    sql = "SELECT * FROM EVENTS WHERE CALL_ID=" & CallId & " ORDER BY EVENT_ID UNION ALL SELECT A.USER_NAME from USERS A INNER JOIN EVENTS B ON A.USER_ID=B.USER_ID WHERE B.CALL_ID=" & CallId & ""
    Thanks...

  2. #2
    Join Date
    Nov 2004
    Location
    Huddinge, Sweden
    Posts
    283
    For the first query you (as the error message suggests) have different number of columns (EVENT_ID,EVENT_DATE,COMMENT) in the select before the UNION than in the select after the UNION (A.USER_NAME).
    What are yuou expecting to achieve with the statement? It looks as if you should break it up into two separate SELECT statments.

    For the second query, you have the same problem. In addition to that - and that's what the error message is about - ORDER BY must be at the end of the entire select.
    If you hit a brick wall, you didn't jump high enough!

  3. #3
    Join Date
    Aug 2007
    Posts
    30

    Re: Incorrect syntax near the keyword Union

    HI.. From this query what i am expecting is... I have to populate the Repeater list with values from two tables(EVENTS AND USERS).COLUMN NAMES from EVENTS I want to select are EVENT_ID,EVENT_DATE,COMMENT and from USERS i want to select USER_NAME WHERE EVENTS.USER_ID = USERS.USER_ID. and then i want to populate the repeater list with these values.How can i do this?
    Query:
    Code:
    SELECT * FROM EVENTS WHERE CALL_ID=" & CallId & " ORDER BY EVENT_ID UNION ALL SELECT A.USER_NAME from USERS A INNER JOIN EVENTS B ON A.USER_ID=B.USER_ID WHERE B.CALL_ID=" & CallId & "
    Thanks.

  4. #4
    Join Date
    Dec 2006
    Posts
    7
    Use a dynamic query with a loop on conditions.

Similar Threads

  1. Replies: 5
    Last Post: 08-18-2006, 02:15 PM
  2. VB6 vs VB.NET...Procedure Calling Syntax
    By Patrick Troughton in forum .NET
    Replies: 78
    Last Post: 08-13-2002, 12:18 PM
  3. Incorrect syntax near 'collate'
    By Daryl in forum Database
    Replies: 0
    Last Post: 03-01-2002, 02:08 PM
  4. Get 10 months forward with select statment
    By Nirit Touboul in forum Database
    Replies: 7
    Last Post: 02-25-2001, 12:34 PM
  5. Incorrect syntax near '#IND'
    By Mario in forum Database
    Replies: 2
    Last Post: 07-29-2000, 08:45 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center