...

View Full Version : How to trim the SQL statement in ASP???



NinjaTurtle
08-27-2004, 09:48 AM
Dear,
i will get the following SQL Statement from another asp page:

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


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?


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

raf
08-27-2004, 12:33 PM
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 :o

miranda
08-28-2004, 12:05 AM
Ninja the way you have it, it should work. Or you could change the code to show something like this



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]"

whammy
09-01-2004, 04:15 AM
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. :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum