simple SQL ELSE IF statement help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adelemb
    New Member
    • Feb 2008
    • 6

    simple SQL ELSE IF statement help

    Hi all,

    We have an Oracle database and my problem is with SQL, apologies if this is posted in the wrong forum.
    I have this SQL statement that all works fine:

    Code:
    var newConn = new openConnection(); 
    if(request.searchBox) 
    { 	
    var searchBox = request.searchBox; 	
    var keywords = searchBox.split(' ') 	 	
    var sql = 'SELECT forumID, masterID, subject, message, datePosted FROM THREADS WHERE approved=1' 	 	
    for(var i=0; i<keywords.length; i++) 	
    { 		
    sql += ' AND UPPER(subject) LIKE UPPER(\'%' + keywords[i] + '%\')'
    sql += ' OR UPPER(message) LIKE UPPER(\'%' + keywords[i] + '%\')' 
    } 	 	
    sql += ' ORDER BY datePosted DESC;'; 
    } 
    else { 	
    document.write("No results found"); 
    }
    My problem is when there are no results to display, I want a sentence to appear saying "No results found" - the ELSE bit of the statement above.
    Can anyone tell me why this doesn't work?

    I know it is probably something obvious to all you clever people!

    Thanks in advance!!
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Which language are you using? You could execute the select statement and then use a count of the number of rows returned.

    Comment

    • amitpatel66
      Recognized Expert Top Contributor
      • Mar 2007
      • 2358

      #3
      In the above code, you have only formed a sql query and stored it in a variable sql. Where and how are you executing your sql?

      If you are using anonymous plsql block in your code then SQL%ROWCOUNT would help you get the count of the records fetched and based on that you can print the result.

      Comment

      • adelemb
        New Member
        • Feb 2008
        • 6

        #4
        Hi,
        we are using an anonymous plsql block so the ROWCOUNT sounds like it could be what I need.
        Ill look into it further, thanks to you both for the suggestion. :-)

        Comment

        Working...