473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Optional Paramter

Is there an elegant way to have an optional parameter in sql string like

Select * from Name where (mytextbox is empty select everyone else select
lastname=mytextbox)
Any direction is appreciated it.
Thanks
Gene
Nov 20 '05 #1
8 952
sg
Assuming you're embedding this in a string, you could say:
sSQL = "Select * from Name " & _
iif(MyTextBox.Text = "", _
"Where Name like '" & MyTextBox.Text & "%'")

-----Original Message-----
Is there an elegant way to have an optional parameter in sql string like
Select * from Name where (mytextbox is empty select everyone else selectlastname=mytextbox)
Any direction is appreciated it.
Thanks
Gene
.

Nov 20 '05 #2
Gene,
This sounds more like a SQL Server or Access question.

You may want to ask this "down the hall" in an SQL Server, Access or the
ado.net newsgroup.

Hope this helps
Jay

"Gene Ariani" <ka*****@comcast.net> wrote in message
news:1P********************@comcast.com...
Is there an elegant way to have an optional parameter in sql string like

Select * from Name where (mytextbox is empty select everyone else select
lastname=mytextbox)
Any direction is appreciated it.
Thanks
Gene

Nov 20 '05 #3
Sg;

Thank you very much for taking the time to response. But I can’t seem to
concatenate your string correctly to make it work.
Thanks
Gene
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4
Cor
Hi Gene,
Select * from Name where (mytextbox is empty select everyone else select
lastname=mytextbox)


What is the benefit of that above
If mytexbox.text ="" then
selectstring = "select * from name"
else
selectstring = "select * from name where lastname"' _
trim(mytextbox.text) & "'"
end if

Or do you want some more processing on your database computer?

I hope this helps a little bit?

Cor
Nov 20 '05 #5

Well I was trying to avoid writing multiple select statement and fit
everthing into one clean sql statement

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #6
Cor
Hi Gene,

I find this a very clean statement and when it is build it is only one thru
step in your computer tested by one digit.

When you put it in a SQL it has to be everytime evaluated and compiled on
your SQL server side.

And this statement shows direct what you are doing.

My choise would be easy.

Cor
Nov 20 '05 #7
Gene,
Then use a variation of Cor's example:

selectstring = "select * from name"

If mytexbox.text <> "" then
selectstring &= " where lastname""' _
trim(mytextbox.text) & """
end if

As Cor stated his original and my modified version are both very easy.

Hope this helps
Jay

"Gene Ariani" <ka*****@comcast.net> wrote in message
news:O9**************@tk2msftngp13.phx.gbl...

Well I was trying to avoid writing multiple select statement and fit
everthing into one clean sql statement

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #8
Thanks everyone for responding.
I basically followed the suggested solutions.

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:uz**************@TK2MSFTNGP09.phx.gbl...
Gene,
Then use a variation of Cor's example:

selectstring = "select * from name"

If mytexbox.text <> "" then
selectstring &= " where lastname""' _
trim(mytextbox.text) & """
end if

As Cor stated his original and my modified version are both very easy.

Hope this helps
Jay

"Gene Ariani" <ka*****@comcast.net> wrote in message
news:O9**************@tk2msftngp13.phx.gbl...

Well I was trying to avoid writing multiple select statement and fit
everthing into one clean sql statement

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eirik Eldorsen | last post by:
I've made a query which works fine. My problem is that Access ask for a paramter value when I run the query, and I can't understand why. The query: SELECT Ordre.ID, Ordre.OpprettetDato,...
5
by: iwdu15 | last post by:
hi, im rewriting my printing class i wrote and i want to make one of the parameters optional, but i cant figure out how to do it. i want it to b something like this Public Sub PrintText(Byval...
7
by: CK | last post by:
I want the procedure to check for the existence of a paramter and if it is there, it will process these instructions, otherwise it will process these instructions. Any ideas? Thanks for your...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
1
by: Tookelso | last post by:
Hello, I would like to have a group of elements which are *required* in one context, but each one is *optional* in another context. For example: I have a configuration file which has a...
5
by: Miro | last post by:
This qustion is probably for people who have created large apps with subs / or functions that have a lot of parameters and used in a lot of places in ur whole app. ( lets say its ur own library...
4
by: Mark Baldwin | last post by:
I have a web page with various controls that supply parameters to an ObjectDataSource. The ObjectDataSource has various methods that allow for filtering of the results...GetProductsByID(),...
12
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
1
by: sugee | last post by:
hi, I need to know the equivalent of optional paramter in c#...?i know that it can be implemented using function overloading..but i need to have only one function which is an important...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.