Forums

This topic is locked

Employee directory search SQL

Posted 12 May 2005 01:39:52
1
has voted
12 May 2005 01:39:52 Charles Crawford posted:
Hi

I'm building a quick-n-dirty employee search for a company intranet. It's very simple: Only 3 search fields (first name, last name, department).

I've managed to set it up so that it returns results for searches on each of the individual search fields i.e. search by a first name and all records with that first name are returned etc. What I want is the ability to refine a search so that when a first name and last name are enetered, only records matching both fields are returned. Ditto for having all 3 fields entered.

Below is the code I have in Dreamweaver:

<%
Dim employeeSearch__varDept
employeeSearch__varDept = "%"
If (Request("dept" <> "" Then
employeeSearch__varDept = Request("dept"
End If
%>
<%
Dim employeeSearch__varFName
employeeSearch__varFName = "%"
If (Request("first_name" <> "" Then
employeeSearch__varFName = Request("first_name"
End If
%>
<%
Dim employeeSearch__varLName
employeeSearch__varLName = "%"
If (Request("last_name" <> "" Then
employeeSearch__varLName = Request("last_name"
End If
%>
<%
Dim employeeSearch
Dim employeeSearch_numRows

Set employeeSearch = Server.CreateObject("ADODB.Recordset"
employeeSearch.ActiveConnection = MM_DQVIntranetDSN_STRING
employeeSearch.Source = "SELECT LastName, FirstName, Department, PhoneNumber, PhoneExtension FROM dbo.EmployeeInfo WHERE (FirstName = '" + Replace(employeeSearch__varFName, "'", "''" + "' AND LastName = '" + Replace(employeeSearch__varLName, "'", "''" + "' AND Department = '" + Replace(employeeSearch__varDept, "'", "''" + "') ORDER BY LastName ASC, FirstName ASC"
employeeSearch.CursorType = 0
employeeSearch.CursorLocation = 2
employeeSearch.LockType = 1
employeeSearch.Open()

employeeSearch_numRows = 0
%>

Reply to this topic