Home > SQL Development > [ASP.Net/Other] Incorrect syntax near the keyword Union

[ASP.Net/Other] Incorrect syntax near the keyword Union



HI.. . 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 & "




When i am using this above query i am getting this error..."Incorrect syntax near the keyword Union " and this error as well..."All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists."



Thanks.

    
Guest


Moved to SQL Development forum as this problem has nothing to do with ASP.Net, but the development of your SQL statement. Please post your questions in the correct forum.

Was this answer helpful ? Yes No   
Guest


when using a UNION clause in your sql statement, there are a few rules.

1) The number of columns requested from both SQL queries must be exact. For example, you can't select 7 columns from the first query and 5 columns from the second query. They both have to be the same number of columns.

2) An ORDER BY clause goes at the end of the UNION query. So the last query in your UNION is the only one to contain the ORDER BY clause.

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved