K
Kenneth Courville
My client has a table with over contact 60000 records. We recently upgraded
to a SQL Server 2000 back-end with MS Access 2002 front-end.
When opening the contacts form with all of these records, I can watch the
MSACCESS process climb to 100+ Mb of RAM. Since their PC's only have 128 Mb
of RAM, this is a problem. The PC's involved tend to run slow and/or crash.
I created a separate form to allow them to specify criteria that will be
used by the contact form. This way, only the records they need to work with
at the time are cached from the server, and not near as much RAM is needed.
My first method of doing this was by creating a string using VBA in the
search form (called Contacts-Find). Upon clicking a button, code is
executed to build the filter, the actual Contacts form is opened, and the
form's server filter item is set to this string.
The problem with this method seemed that the filter would sometimes be saved
with the form, and that same search criteria is "stuck" in there when the
next person tries to execute a search.
For my next method, I tried creating a stored procecure, which follows
below. In addition, the Input Parameters option for the Contact form is set
to (not complete text):
"@SearchType=forms![contacts-find]!SearchType,@ContactID=forms![contacts-fin
d]!ContactID,@StoreNum=forms![contacts-find]!StoreNum,@CompanyName=forms![co
ntacts-find]!CompanyName,@FirstName=forms![contacts-find]!FirstName,@LastNam
e=forms![contacts-find]!LastName,@Address=forms![contacts-find]!Address,@Cit
y=forms![contacts-find]!City..."
Basically, the parameter @SearchType is used to determine whether to perform
and "OR" query or an "AND" query. The problem now is that we cannot
effectively perform an "AND" query. This occurs because the client may not
necessary provide data for all of the input parameters below, which results
in search for records that have to have blank or 0 in the field.
My question is... is there a better way to do this, or is there a way to fix
my methods listed above?
ALTER PROCEDURE dbo.spFilterContactsTest
(@SearchType char(3),
@ContactID int,
@StoreNum float,
@CompanyName nvarchar(50),
@FirstName nvarchar(20),
@LastName nvarchar(25),
@Address nvarchar(40),
@City nvarchar(25),
@StateOrProvince nvarchar(2),
@PostalCode nvarchar(10),
@EmailName nvarchar(50),
@WorkPhone nvarchar(14),
@FaxNumber nvarchar(14),
@KeyAcctMgr nvarchar(25),
@StatusTypeID int)
AS
IF @CompanyName='' SET @CompanyName='%'
IF @FirstName ='' SET @FirstName ='%'
IF @LastName ='' SET @LastName ='%'
IF @Address ='' SET @Address ='%'
IF @City ='' SET @City ='%'
IF @StateOrProvince ='' SET @StateOrProvince ='%'
IF @PostalCode ='' SET @PostalCode ='%'
IF @EmailName ='' SET @EmailName ='%'
IF @WorkPhone ='' SET @WorkPhone ='%'
IF @FaxNumber ='' SET @FaxNumber ='%'
IF @WorkPhone ='' SET @WorkPhone ='%'
IF @KeyAcctMgr='' SET @KeyAcctMgr='%'
IF @SearchType='OR' -- perform an "OR" search
BEGIN
SELECT ContactID, StoreNum, CompanyName, BuildingName, FirstName, LastName,
Address, City, StateOrProvince, PostalCode, EmailName, WorkPhone,
WorkExtension, FaxNumber, MobilePhone, ReferredBy, Notes, GEOMarket, Area,
District, CVSDistrict, ContactTypeID, StatusTypeID,
NumberOfEmployees, FluClinicMailing, KeyAcctMgr, AcctMaintRep,
SecondaryContact, SecondaryContactTitle, SecondaryPhone, SecondaryEmail,
ClinicCompetition, Flag, Title
FROM dbo.Contacts
WHERE (ContactID = @ContactID) OR
(StoreNum = @StoreNum) OR
(CompanyName LIKE @CompanyName) OR
(FirstName LIKE @FirstName) OR
(LastName LIKE @LastName) OR
(Address LIKE @Address) OR
(City LIKE @City) OR
(StateOrProvince LIKE @StateOrProvince) OR
(PostalCode LIKE @PostalCode) OR
(EmailName LIKE @EmailName) OR
(WorkPhone LIKE @WorkPhone) OR
(FaxNumber LIKE @FaxNumber) OR
(KeyAcctMgr LIKE @KeyAcctMgr) OR
(StatusTypeID = @StatusTypeID)
END
ELSE -- Perform an "AND" search
BEGIN
SELECT ContactID, StoreNum, CompanyName, BuildingName, FirstName, LastName,
Address, City, StateOrProvince, PostalCode, EmailName, WorkPhone, WorkExtens
ion, FaxNumber, MobilePhone, ReferredBy, Notes, GEOMarket, Area, District,
CVSDistrict, ContactTypeID, StatusTypeID,
NumberOfEmployees, FluClinicMailing, KeyAcctMgr, AcctMaintRep,
SecondaryContact, SecondaryContactTitle, SecondaryPhone, SecondaryEmail,
ClinicCompetition, Flag, Title
FROM dbo.Contacts
WHERE (ContactID = @ContactID) AND
(StoreNum = @StoreNum) AND
(CompanyName LIKE @CompanyName) AND
(FirstName LIKE @FirstName) AND
(LastName LIKE @LastName) AND
(Address LIKE @Address) AND
(City LIKE @City) AND
(StateOrProvince LIKE @StateOrProvince) AND
(PostalCode LIKE @PostalCode) AND
(EmailName LIKE @EmailName) AND
(WorkPhone LIKE @WorkPhone) AND
(FaxNumber LIKE @FaxNumber) AND
(KeyAcctMgr LIKE @KeyAcctMgr) AND
(StatusTypeID = @StatusTypeID)
END
to a SQL Server 2000 back-end with MS Access 2002 front-end.
When opening the contacts form with all of these records, I can watch the
MSACCESS process climb to 100+ Mb of RAM. Since their PC's only have 128 Mb
of RAM, this is a problem. The PC's involved tend to run slow and/or crash.
I created a separate form to allow them to specify criteria that will be
used by the contact form. This way, only the records they need to work with
at the time are cached from the server, and not near as much RAM is needed.
My first method of doing this was by creating a string using VBA in the
search form (called Contacts-Find). Upon clicking a button, code is
executed to build the filter, the actual Contacts form is opened, and the
form's server filter item is set to this string.
The problem with this method seemed that the filter would sometimes be saved
with the form, and that same search criteria is "stuck" in there when the
next person tries to execute a search.
For my next method, I tried creating a stored procecure, which follows
below. In addition, the Input Parameters option for the Contact form is set
to (not complete text):
"@SearchType=forms![contacts-find]!SearchType,@ContactID=forms![contacts-fin
d]!ContactID,@StoreNum=forms![contacts-find]!StoreNum,@CompanyName=forms![co
ntacts-find]!CompanyName,@FirstName=forms![contacts-find]!FirstName,@LastNam
e=forms![contacts-find]!LastName,@Address=forms![contacts-find]!Address,@Cit
y=forms![contacts-find]!City..."
Basically, the parameter @SearchType is used to determine whether to perform
and "OR" query or an "AND" query. The problem now is that we cannot
effectively perform an "AND" query. This occurs because the client may not
necessary provide data for all of the input parameters below, which results
in search for records that have to have blank or 0 in the field.
My question is... is there a better way to do this, or is there a way to fix
my methods listed above?
ALTER PROCEDURE dbo.spFilterContactsTest
(@SearchType char(3),
@ContactID int,
@StoreNum float,
@CompanyName nvarchar(50),
@FirstName nvarchar(20),
@LastName nvarchar(25),
@Address nvarchar(40),
@City nvarchar(25),
@StateOrProvince nvarchar(2),
@PostalCode nvarchar(10),
@EmailName nvarchar(50),
@WorkPhone nvarchar(14),
@FaxNumber nvarchar(14),
@KeyAcctMgr nvarchar(25),
@StatusTypeID int)
AS
IF @CompanyName='' SET @CompanyName='%'
IF @FirstName ='' SET @FirstName ='%'
IF @LastName ='' SET @LastName ='%'
IF @Address ='' SET @Address ='%'
IF @City ='' SET @City ='%'
IF @StateOrProvince ='' SET @StateOrProvince ='%'
IF @PostalCode ='' SET @PostalCode ='%'
IF @EmailName ='' SET @EmailName ='%'
IF @WorkPhone ='' SET @WorkPhone ='%'
IF @FaxNumber ='' SET @FaxNumber ='%'
IF @WorkPhone ='' SET @WorkPhone ='%'
IF @KeyAcctMgr='' SET @KeyAcctMgr='%'
IF @SearchType='OR' -- perform an "OR" search
BEGIN
SELECT ContactID, StoreNum, CompanyName, BuildingName, FirstName, LastName,
Address, City, StateOrProvince, PostalCode, EmailName, WorkPhone,
WorkExtension, FaxNumber, MobilePhone, ReferredBy, Notes, GEOMarket, Area,
District, CVSDistrict, ContactTypeID, StatusTypeID,
NumberOfEmployees, FluClinicMailing, KeyAcctMgr, AcctMaintRep,
SecondaryContact, SecondaryContactTitle, SecondaryPhone, SecondaryEmail,
ClinicCompetition, Flag, Title
FROM dbo.Contacts
WHERE (ContactID = @ContactID) OR
(StoreNum = @StoreNum) OR
(CompanyName LIKE @CompanyName) OR
(FirstName LIKE @FirstName) OR
(LastName LIKE @LastName) OR
(Address LIKE @Address) OR
(City LIKE @City) OR
(StateOrProvince LIKE @StateOrProvince) OR
(PostalCode LIKE @PostalCode) OR
(EmailName LIKE @EmailName) OR
(WorkPhone LIKE @WorkPhone) OR
(FaxNumber LIKE @FaxNumber) OR
(KeyAcctMgr LIKE @KeyAcctMgr) OR
(StatusTypeID = @StatusTypeID)
END
ELSE -- Perform an "AND" search
BEGIN
SELECT ContactID, StoreNum, CompanyName, BuildingName, FirstName, LastName,
Address, City, StateOrProvince, PostalCode, EmailName, WorkPhone, WorkExtens
ion, FaxNumber, MobilePhone, ReferredBy, Notes, GEOMarket, Area, District,
CVSDistrict, ContactTypeID, StatusTypeID,
NumberOfEmployees, FluClinicMailing, KeyAcctMgr, AcctMaintRep,
SecondaryContact, SecondaryContactTitle, SecondaryPhone, SecondaryEmail,
ClinicCompetition, Flag, Title
FROM dbo.Contacts
WHERE (ContactID = @ContactID) AND
(StoreNum = @StoreNum) AND
(CompanyName LIKE @CompanyName) AND
(FirstName LIKE @FirstName) AND
(LastName LIKE @LastName) AND
(Address LIKE @Address) AND
(City LIKE @City) AND
(StateOrProvince LIKE @StateOrProvince) AND
(PostalCode LIKE @PostalCode) AND
(EmailName LIKE @EmailName) AND
(WorkPhone LIKE @WorkPhone) AND
(FaxNumber LIKE @FaxNumber) AND
(KeyAcctMgr LIKE @KeyAcctMgr) AND
(StatusTypeID = @StatusTypeID)
END