Hi, I've got a major headache with a SQL Union statement.
Basically I'm running a SQL Union statement in ASP that is not returning the first few unions. But if I run the SQL in enterprise manager it runs fine. I can't find anything on the web that even remotely describes this problem so I'm really hoping someone here can answer it for me.
The ASP code is as follows:
DSNtemp = "Provider=SQLOLEDB;Data Source=" & data_source & ";database=" & database & ";uid=" & uid & ";pwd=" & pwd & ";"
set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.ConnectionTimeout = 15
MyConn.CommandTimeout = 10
MyConn.Mode = 1 'adModeRead
MyConn.Errors.Clear
Err.Clear
if MyConn.state = 0 then
MyConn.Open DSNtemp
end if
set rsSetup = Server.CreateObject("ADODB.Recordset")
rsSetup.CursorLocation = 3
rsSetup.CacheSize = 20
rsSetup.open searchSQL, MyConn, 1, 1
if rsSetup.RecordCount > 0 then
rsSetup.MoveFirst
rsSetup.PageSize = 20
TotalPages = rsSetup.PageCount
rsSetup.AbsolutePage = CurPage
searchdata = rsSetup.getrows
searchnumcols = ubound(searchdata,1)
searchnumrows = ubound(searchdata,2)
FOR searchrowcounter = 0 TO searchnumrows
<output results>
NEXT
end if
And an example of the generated SQL is:
SELECT TOP (500) link_id, searchorder FROM
(
(SELECT link_id, '0' AS searchorder FROM links AS S WHERE (LINK_ADDRESS LIKE '%Level 5, 12 Pitt STREET%' OR LINK_ADDRESS LIKE '%Level 5, 12 Pitt ST%') AND (LINK_STATE = 'NSW') AND (LINK_CITY LIKE '%Sydney%') AND (LINK_ZIP = '2000'))
UNION
(SELECT link_id, '1' AS searchorder FROM links AS S WHERE (LINK_ADDRESS LIKE '%Pitt STREET%' OR LINK_ADDRESS LIKE '%Pitt ST%') AND (LINK_STATE = 'NSW') AND (LINK_CITY LIKE '%Sydney%') AND (LINK_ZIP = '2000'))
UNION
(SELECT link_id, '2' AS searchorder FROM links AS S WHERE (LINK_ADDRESS LIKE '%Pitt%') AND (LINK_STATE = 'NSW') AND (LINK_CITY LIKE '%Surry Hills%') AND (LINK_ZIP = '2000'))
UNION
(SELECT link_id, '3' AS searchorder FROM links AS S WHERE (LINK_STATE = 'NSW') AND (LINK_CITY LIKE '%Sydney%') AND (LINK_ZIP = '2000'))
UNION
(SELECT link_id, '4' AS searchorder FROM links AS S WHERE (LINK_STATE = 'NSW') AND (LINK_CITY LIKE '%Sydney%'))
UNION
(SELECT link_id, '5' AS searchorder FROM links AS S WHERE (LINK_ZIP = '2000'))
UNION
(SELECT link_id, '6' AS searchorder FROM links AS S WHERE (LINK_STATE = 'NSW'))
) AS searchresults
ORDER BY searchorder ASC
ASP will only display results from where searchorder equals 2???