473,387 Members | 1,483 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.

Best way to search for all records (Using a Case Statement in a SP)

I have a form with a dropdown or combo box, the user can select <All>
or pick a user name. If they pick a user name my where clause works
fine, buts what's the best way to write "Select All" if they choose
the <All>

This is what I have so far, but I don't think I should be using the
LIKE operator.

WHERE tblCase.qarep LIKE CASE @myqarep WHEN '<All>' THEN '%' ELSE
@myqarep END
and tblOffice.officecode LIKE CASE @myoffice WHEN -1 THEN '%' ELSE
@myoffice END

thanks for your help!!
Jul 20 '05 #1
4 1314
On 13 Sep 2004 10:47:21 -0700, PaulMac wrote:
I have a form with a dropdown or combo box, the user can select <All>
or pick a user name. If they pick a user name my where clause works
fine, buts what's the best way to write "Select All" if they choose
the <All>

This is what I have so far, but I don't think I should be using the
LIKE operator.

WHERE tblCase.qarep LIKE CASE @myqarep WHEN '<All>' THEN '%' ELSE
@myqarep END
and tblOffice.officecode LIKE CASE @myoffice WHEN -1 THEN '%' ELSE
@myoffice END

thanks for your help!!


Hi Paul,

You could use this:

WHERE tblCase.qarep = CASE @myqrep
WHEN '<All>' THEN tblCase.qarep
ELSE @myqrep
END
AND tblOffice.officecode = CASE @myoffice
WHEN -1 THEN tblOffice.officecode
ELSE @myoffice
END

An alternative that's a bit more work to create but that will probably
perform better is to write different versions of the query; use IF to
select which search arguments are set to All and which are set to a value
and then execute the correct version of the query.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2
PaulMac (pa********@hotmail.com) writes:
I have a form with a dropdown or combo box, the user can select <All>
or pick a user name. If they pick a user name my where clause works
fine, buts what's the best way to write "Select All" if they choose
the <All>

This is what I have so far, but I don't think I should be using the
LIKE operator.

WHERE tblCase.qarep LIKE CASE @myqarep WHEN '<All>' THEN '%' ELSE
@myqarep END
and tblOffice.officecode LIKE CASE @myoffice WHEN -1 THEN '%' ELSE
@myoffice END


Since it's a combo, LIKE appears to be a bit of overkill. The normal
procedure is to pass NULL when you want all:

WHERE (qarep = @myqarep OR @myqarep IS NULL)
AND (officecode = @myoffice OR @myoffice IS NULL)

But of course this works too:

WHERE (qarep = @myqarep OR @myqarep = '<All>')
AND (officecode = @myoffice OR @myoffice = -1)

At least as long as you don't localize the string...

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
I will not suggest putting a CASE command in the WHERE clause, you may
just want to use "if" control statement to separate two code blocks
which will be more efficient at database level.

IF Boolean_expression
{ sql_statement | statement_block }
[
ELSE
{ sql_statement | statement_block } ]


pa********@hotmail.com (PaulMac) wrote in message news:<1e**************************@posting.google. com>...
I have a form with a dropdown or combo box, the user can select <All>
or pick a user name. If they pick a user name my where clause works
fine, buts what's the best way to write "Select All" if they choose
the <All>

This is what I have so far, but I don't think I should be using the
LIKE operator.

WHERE tblCase.qarep LIKE CASE @myqarep WHEN '<All>' THEN '%' ELSE
@myqarep END
and tblOffice.officecode LIKE CASE @myoffice WHEN -1 THEN '%' ELSE
@myoffice END

thanks for your help!!

Jul 20 '05 #4
Hi Hugo

That worked perfectly...Thank You!!

Hugo Kornelis <hugo@pe_NO_rFact.in_SPAM_fo> wrote in message news:<3e********************************@4ax.com>. ..
On 13 Sep 2004 10:47:21 -0700, PaulMac wrote:
I have a form with a dropdown or combo box, the user can select <All>
or pick a user name. If they pick a user name my where clause works
fine, buts what's the best way to write "Select All" if they choose
the <All>

This is what I have so far, but I don't think I should be using the
LIKE operator.

WHERE tblCase.qarep LIKE CASE @myqarep WHEN '<All>' THEN '%' ELSE
@myqarep END
and tblOffice.officecode LIKE CASE @myoffice WHEN -1 THEN '%' ELSE
@myoffice END

thanks for your help!!


Hi Paul,

You could use this:

WHERE tblCase.qarep = CASE @myqrep
WHEN '<All>' THEN tblCase.qarep
ELSE @myqrep
END
AND tblOffice.officecode = CASE @myoffice
WHEN -1 THEN tblOffice.officecode
ELSE @myoffice
END

An alternative that's a bit more work to create but that will probably
perform better is to write different versions of the query; use IF to
select which search arguments are set to All and which are set to a value
and then execute the correct version of the query.

Best, Hugo

Jul 20 '05 #5

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

Similar topics

4
by: Lucky | last post by:
I have a vb.net windows app that connects to an access database. The database has 1 table. One of the columns is called "Address". A user enters any address into a textbox (txtValue) then clicks...
1
by: arikatla | last post by:
We are using SQL Server 2000 database (with sp3) and recently we faced an interesting issue with full text search. According to SQLServer help page "AND | AND NOT | OR Specifies a logical...
2
by: misschristalee | last post by:
I'm having a brain blockage day.... Scenario: Search Form with 6 text boxes Query has same six fields Each has this IIF: IIf(IsNull(!!),"",!!) with each dictating the correct text box of...
3
by: David Altemir | last post by:
I have a table in MS Access 2003 that contains records that I would like to copy to the end of the table. There is one slight deviation from just doing a straightforwared COPY, however, in that I...
1
by: Chris Uwins | last post by:
Hi there, i know theres a number of ways I can achieve this but want to know the best, (but still quite simple). Up until a year ago I never used Access but have designed a few databases for...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
4
by: bj daniels | last post by:
I have a sql server (2000) and I want to add a search capability to my asp.net page. It will search an Articles table - in particular the 'Article' field (ntext). I started with the following...
0
by: cyprian.pl | last post by:
Hello, I would like to ask some opinions on the best DB strategy for the following problem: I have a table containing information about artists (names, dates, descriptions in three languages...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.