By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,806 Members | 1,787 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,806 IT Pros & Developers. It's quick & easy.

Optional Parameter in a SQL Function -- selecting all

P: 47
Hi, I need some help.

I have a function with a parameter that runs a query. I'd like the parameter to be optional, so that if the user enters nothing or "all" the query will select all records.

Is there something I can do to my WHERE clause so that it will select all records based on the value of my parameter?

(Actually, the real function has three parameters, but the issue is easier to explain as if there's only one.)

I'm baffled. Thanks a lot,

Mar 12 '09 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 2,878
Assign NULL as the default value to your parameter. Use this technique on your WHERE clause

Expand|Select|Wrap|Line Numbers
  1. SELECT...FROM...
  2. WHERE yourfiltercolumn = isnull(@parameter, yourfiltercolumn)

-- CK
Mar 12 '09 #2

P: 47
Thanks CK! It worked
Mar 12 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.