Select all Records using VBS/Query in Sql

I'm trying to do something similar to : strSQL = "SELECT * FROM dbo.ActivityLog Where Username = '*'  and Action = '*' and GroupName = '*' Order BY [TrueDate] DESC".

Leaving out  "where username = ..." is not an option.  Maybe there is a better way to do this, but I'll try to explain why I need this...

I have a web page where a user can select different criteria, based on what they'd like to see from the query. There is an option of 'Group name' , 'username', and 'action'. I would like to include all data, if an option is not selected, and only the data that is selected.
Darkejo1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wynandkunkelCommented:
Just change the '*' to '%'.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
there is no "star" option ( * ) when assigning a value to a column in a where clause, one just leaves out that column.

why can't you leave out the username column when no options are selected?
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
If you are using sql server it would be

Where Username like '%'

because the percent sign is the wild card.  

However, having multiple wildcards can slow things down.  If you don't need them, then don't use them.  It does not make sense to use where username like '%' when leaving it does the same thing.

What you probably should be doing is building your sql statement on the fly.   As example:


strSQL =SELECT * FROM dbo.ActivityLog Where 

if request.form("username")<>"" then ' no we know there is data
    ' next it is always good to clean your data input, never trust it
    ' below code just removes single quotes as an example
      username=replace(request.form("username"),"'","")

      strSQL=strSQL&" Username like '"&username&"' "
end if

Open in new window

From there, keep building your sql statement. Notice that if we don't get username input, we just don't put it in the WHERE clause.  This will speed things up on the data end.
0
Darkejo1Author Commented:
Thanks for your response.

I Just tested and that does not work.

To clarify, I am running MS SQL Server 2005 and I used this query to test:

The table name is "ActivityLog" If I try

Select * From ActivityLog Where [Username] = '%'

0 fields are returned.


Correction..It looks like I need to change the = to Like.
0
Darkejo1Author Commented:
Thanks!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.