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.
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.

Just change the '*' to '%'.

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 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?
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

      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.
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.
Darkejo1Author Commented:
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.