Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Incorrect Syntax with UNION
Message
 
 
To
23/11/2008 07:24:35
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01363694
Message ID:
01363695
Views:
5
This message has been marked as the solution to the initial question of the thread.
>Hello, I'm trying to create a simple UNION but is not working is displaying the next message:
>
>TITLE: Microsoft Report Designer
>------------------------------
>
>An error occurred while executing the query.
>Incorrect syntax near the keyword 'UNION'.
>
>------------------------------
>ADDITIONAL INFORMATION:
>
>Incorrect syntax near the keyword 'UNION'. (Microsoft SQL Server, Error: 156)
>
>For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.1406&EvtSrc=MSSQLServer&EvtID=156&LinkId=20476
>
>------------------------------
>BUTTONS:
>
>OK
>------------------------------
>
>And this is my UNION:
>
>SELECT IdUsuario, Nombre
>FROM Usuario
>ORDER BY Nombre
>UNION
>SELECT Null, 'All'
>
>How can I solve this?

Try
SELECT IdUsuario, Nombre
FROM Usuario
UNION
SELECT Null as IdUsario, 'All' as Nombre
ORDER BY Nombre
If you want All to be the last entry, you may try
SELECT IdUsuario, Nombre, 1 as iOrder
FROM Usuario
UNION
SELECT Null as IdUsario, 'All' as Nombre, 2 as iOrder
ORDER BY iOrder, Nombre
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform