SQL Union/ASP problem

Thread Solved

Join Date: Sep 2008
Posts: 9
Reputation: EddySR is an unknown quantity at this point 
Solved Threads: 0
EddySR EddySR is offline Offline
Newbie Poster

SQL Union/ASP problem

 
0
  #1
Sep 22nd, 2008
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:
  1. DSNtemp = "Provider=SQLOLEDB;Data Source=" & data_source & ";database=" & database & ";uid=" & uid & ";pwd=" & pwd & ";"
  2.  
  3. set MyConn = Server.CreateObject("ADODB.Connection")
  4. MyConn.ConnectionTimeout = 15
  5. MyConn.CommandTimeout = 10
  6. MyConn.Mode = 1 'adModeRead
  7. MyConn.Errors.Clear
  8. Err.Clear
  9.  
  10. if MyConn.state = 0 then
  11. MyConn.Open DSNtemp
  12. end if
  13.  
  14. set rsSetup = Server.CreateObject("ADODB.Recordset")
  15.  
  16. rsSetup.CursorLocation = 3
  17. rsSetup.CacheSize = 20
  18. rsSetup.open searchSQL, MyConn, 1, 1
  19.  
  20. if rsSetup.RecordCount > 0 then
  21. rsSetup.MoveFirst
  22. rsSetup.PageSize = 20
  23. TotalPages = rsSetup.PageCount
  24. rsSetup.AbsolutePage = CurPage
  25. searchdata = rsSetup.getrows
  26. searchnumcols = ubound(searchdata,1)
  27. searchnumrows = ubound(searchdata,2)
  28.  
  29. FOR searchrowcounter = 0 TO searchnumrows
  30. <output results>
  31. NEXT
  32. end if

And an example of the generated SQL is:
  1. SELECT TOP (500) link_id, searchorder FROM
  2. (
  3. (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'))
  4. UNION
  5. (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'))
  6. UNION
  7. (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'))
  8. UNION
  9. (SELECT link_id, '3' AS searchorder FROM links AS S WHERE (LINK_STATE = 'NSW') AND (LINK_CITY LIKE '%Sydney%') AND (LINK_ZIP = '2000'))
  10. UNION
  11. (SELECT link_id, '4' AS searchorder FROM links AS S WHERE (LINK_STATE = 'NSW') AND (LINK_CITY LIKE '%Sydney%'))
  12. UNION
  13. (SELECT link_id, '5' AS searchorder FROM links AS S WHERE (LINK_ZIP = '2000'))
  14. UNION
  15. (SELECT link_id, '6' AS searchorder FROM links AS S WHERE (LINK_STATE = 'NSW'))
  16. ) AS searchresults
  17. ORDER BY searchorder ASC

ASP will only display results from where searchorder equals 2???
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 9
Reputation: EddySR is an unknown quantity at this point 
Solved Threads: 0
EddySR EddySR is offline Offline
Newbie Poster

Re: SQL Union/ASP problem

 
0
  #2
Sep 22nd, 2008
Ok, thats the weirdest thing ever. When I copied the SQL statement from enterprise manager and run it in ASP it works fine. I then matched the ASP generated SQL statement to enterprise manager version of statement "to the character" and it still doesn't work. What the heck! ???
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,162
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 138
dickersonka dickersonka is offline Offline
Veteran Poster

Re: SQL Union/ASP problem

 
0
  #3
Sep 22nd, 2008
sure you are hitting the same database?

also, is it a long running query? if so, might want up your limits
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 9
Reputation: EddySR is an unknown quantity at this point 
Solved Threads: 0
EddySR EddySR is offline Offline
Newbie Poster

Re: SQL Union/ASP problem

 
0
  #4
Sep 22nd, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MS SQL Forum


Views: 1313 | Replies: 3
Thread Tools Search this Thread



Tag cloud for MS SQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC