Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to trim the SQL statement in ASP???

    Dear,
    i will get the following SQL Statement from another asp page:
    Code:
    sql= "SELECT * FROM SalesOrder WHERE name like 'abc%' and [issued by]='"&Session("User ID")&"' and status<>'Approved' ORDER BY [SO ID]"
    From the above SQL statement, it will only show those Sales order which Issued by the particular user. But now i want to check if allow to view all Sales Order, then the SQL statement should be changed to

    Code:
    sql= "SELECT * FROM SalesOrder WHERE name like 'abc%' and status<>'Approved' ORDER BY [SO ID]"
    how to do it in ASP If then else statement?
    Code:
    If viewall=true then
    sql= "SELECT * FROM SalesOrder WHERE name like 'abc%' and status<>'Approved' ORDER BY [SO ID]"
    
    else
    sql= "SELECT * FROM SalesOrder WHERE name like 'abc%' and [issued by]='"&Session("User ID")&"' and status<>'Approved' ORDER BY [SO ID]"
    end if
    Last edited by NinjaTurtle; 08-27-2004 at 08:53 AM.
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you'll need to use a regex-replace for that.
    replace the clause "and [issued by]='avalue'" with ''

    sorry but my regex-knowledge for ASP is to rusty to write the regex out
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,071
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Ninja the way you have it, it should work. Or you could change the code to show something like this

    Code:
    WhereClause = "WHERE name like 'abc%' and status<>'Approved'"
    If viewall = False Then WhereClause = WhereClause & " and [issued by]='"&Session("User ID") & "'"
    sql= "SELECT * FROM SalesOrder " & WhereClause  & "ORDER BY [SO ID]"

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If Miranda's solution doesn't work, please response.write the sql statement out after the if/then statement - that's the best thing to do when troubleshooting ASP in almost any situation.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •