Ask a Question related to ASP Database, Design and Development.
-
MDW #1
Sorting With a UNION Query?
Hey all,
I'm working with SQL server 2000 (upsized from MS Access 2000) and I've been able to reconcile all my SQL differences but one. I build a fairly complex recordset that consists of a UNION from two different SELECT statements. It ends up looking like this:
SELECT
Col1,
Col2,
Col3
FROM
Table1 WHERE Col1='aaa' ORDER BY Col1 ASC, Col2 ASC
UNION SELECT
Col2
Col5
'N/A'
FROM
Table2 WHERE Col5='bbb'
When my ASP was hooked into Access, that statement executed fine. However, SQL server returns an error that says "Invalid syntax near keyword UNION". I've tried surrounding the SELECT statements in parenthasees (SELECT ... ORDER BY ...) UNION (SELECT ...), but that didn't work. Access was happy with it either way.
Any suggestions as to what I could be doing wrong?
MDW Guest
-
#39270 [NEW]: mysql_field_table() Doesnt Work With UNION Query
From: jkeller at fieldtechnologies dot com Operating system: WinXp, Win 2003 PHP version: 5.1.6 PHP Bug Type: MySQL related... -
Getting recordcount from resultset of 'union' query
Hi, I need to find out the number of records in the resultset of a union of 2 queries. E.g. "select ID from Pages where numPageCatID = " &... -
Sorting a query based on URL variable
Well i dont think it's what you looking for but i made this exemple , check if you need somthing more simple i will chwck for you <cfif... -
ORDER BY in UNION query
Hi, I need to use ORDER BY clause in a UNION query and the Order BY columns are not included in the SELECT statement. I tried like this (select... -
UNION QUERY
I've just installed version 4 of MySql and understand this may be a question regarding my syntax, not PHP, but I'm receiving errors from the... -
Chris Hohmann #2
Re: Sorting With a UNION Query?
"MDW" <MDW@discussions.microsoft.com> wrote in message
news:D5B5EE74-8269-46E2-8A56-D79F60705EB9@microsoft.com...been able to reconcile all my SQL differences but one. I build a fairly> Hey all,
>
> I'm working with SQL server 2000 (upsized from MS Access 2000) and I've
complex recordset that consists of a UNION from two different SELECT
statements. It ends up looking like this:However, SQL server returns an error that says "Invalid syntax near keyword>
> SELECT
> Col1,
> Col2,
> Col3
> FROM
> Table1 WHERE Col1='aaa' ORDER BY Col1 ASC, Col2 ASC
> UNION SELECT
> Col2
> Col5
> 'N/A'
> FROM
> Table2 WHERE Col5='bbb'
>
> When my ASP was hooked into Access, that statement executed fine.
UNION". I've tried surrounding the SELECT statements in parenthasees (SELECT
.... ORDER BY ...) UNION (SELECT ...), but that didn't work. Access was
happy with it either way.Put the ORDER BY clause at the end. See example (f) under the "SELECT>
> Any suggestions as to what I could be doing wrong?
Examples" topic in BOL. Note, that's a lowercase "f".
Chris Hohmann Guest
-
Aaron [SQL Server MVP] #3
Re: Sorting With a UNION Query?
You can only sort the result as a whole, not the individual queries.
--
[url]http://www.aspfaq.com/[/url]
(Reverse address to reply.)
"MDW" <MDW@discussions.microsoft.com> wrote in message
news:D5B5EE74-8269-46E2-8A56-D79F60705EB9@microsoft.com...been able to reconcile all my SQL differences but one. I build a fairly> Hey all,
>
> I'm working with SQL server 2000 (upsized from MS Access 2000) and I've
complex recordset that consists of a UNION from two different SELECT
statements. It ends up looking like this:However, SQL server returns an error that says "Invalid syntax near keyword>
> SELECT
> Col1,
> Col2,
> Col3
> FROM
> Table1 WHERE Col1='aaa' ORDER BY Col1 ASC, Col2 ASC
> UNION SELECT
> Col2
> Col5
> 'N/A'
> FROM
> Table2 WHERE Col5='bbb'
>
> When my ASP was hooked into Access, that statement executed fine.
UNION". I've tried surrounding the SELECT statements in parenthasees (SELECT
.... ORDER BY ...) UNION (SELECT ...), but that didn't work. Access was
happy with it either way.>
> Any suggestions as to what I could be doing wrong?
Aaron [SQL Server MVP] Guest



Reply With Quote

