Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 select query with union

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2010-09-20 : 14:15:21
I am trying to create a union select query, but getting a message saying:
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.
Can you please tell me, what mistake am i doing.

Select 0 as ProgID, '* Select *' as ProgNO,null as AccessMode 

union

SELECT A.ProgID, B.ProgNO, B.ProgName, A.AccessMode FROM TAB_Programs AS A JOIN
TAB_Programs AS B ON A.ProgID = B.ProgID
WHERE A.UserID = @UserID AND A.AccessMode = 2 AND A.Deleted = '0'


Thank you very much for the helpful info.

X002548
Not Just a Number

15586 Posts

Posted - 2010-09-20 : 14:32:31
isn't the error self explanatory?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx





Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2010-09-20 : 14:39:42
Got it missed one.

Thanks.

quote:
Originally posted by X002548

isn't the error self explanatory?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx







Go to Top of Page
   

- Advertisement -