| | |
SQL Union/ASP problem
Please support our MS SQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 9
Reputation:
Solved Threads: 0
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:
And an example of the generated SQL is:
ASP will only display results from where searchorder equals 2???
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:
ASP Syntax (Toggle Plain Text)
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:
MS SQL Syntax (Toggle Plain Text)
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???
•
•
Join Date: Aug 2008
Posts: 1,162
Reputation:
Solved Threads: 138
sure you are hitting the same database?
also, is it a long running query? if so, might want up your limits
also, is it a long running query? if so, might want up your limits
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Sep 2008
Posts: 9
Reputation:
Solved Threads: 0
I figured it out last night. Its a bit embarrassing! All it was that some of the generated values had consecutive whitespaces. It doesn't show up in html or pasted into a text editor because the browser automatically strips extra whitespace. It wasn't until I exported it with a urlencode function that I realized my mistake. Duh!
Thanks anyway
Thanks anyway
![]() |
Similar Threads
- SQL String question (ASP)
Other Threads in the MS SQL Forum
- Previous Thread: adding columns of a table
- Next Thread: Get the data of tow rpws in one rows
Views: 1313 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for MS SQL
"last age autogrowth business connectingtodatabaseinuse count cursor data database dateadd datediff datepart day" dbsize deadlock delete_trigger exploit getdate hack highperformancecomputing hpc hpcserver2008 ibm iis limit live loop maximum microsoft ms mssql multiple multithreading news number password permission position query reporting result security server services sets single source sql sql-injection sqlserver sqlserver2005 subtype supercomputing supertype tables uniqueid update view weekday






