RE: Stored Procedure with Multiple conditions
From: Alejandro Mesa (AlejandroMesa_at_discussions.microsoft.com)
Date: 01/12/05
- Next message: Hank: "how to convert 'if...else...' to CASE"
- Previous message: Alejandro Mesa: "RE: Log stored proc. errors to SQL log or Event Log"
- In reply to: Drew: "Stored Procedure with Multiple conditions"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 12 Jan 2005 07:53:10 -0800
Take your time reading these outstanding articles written by Erland
Sommarskog, there you will find the answer to your question.
Arrays and Lists in SQL Server
http://www.sommarskog.se/arrays-in-sql.html
Dynamic Search Conditions in T-SQL
http://www.sommarskog.se/dyn-search.html
AMB
"Drew" wrote:
> I am using Access to report out of my SQL Server database. I am building
> stored procedures and then using them for the reports. Everything is
> working fine, but I have hit a snag. I need to build a report to show
> employee information. I have the following SP,
>
> CREATE PROCEDURE spEmpInfo
> @EmpSSNEntry varchar(15),
> AS
> IF @EmpSSNEntry IS NULL
> SELECT E.EmpID, P.PosID, E.EmpFName, E.EmpMName, E.EmpLName,
> E.EmpSuffix, E.EmpShift, E.EmpStatus, E.EmpActive, P.PosRoleCode,
> P.PosTimeKeeper, C.CostCenter, EF.EmpSalary,
> EF.EmpDirectDeposit, EF.EmpInsID, EP.EmpRace, EP.EmpSex, EP.EmpDOB,
> EP.EmpStateBegDate,
> EP.EmpSWVTCBegDate, EP.EmpSWVTCSepDate,
> EP.EmpPositionBegDate, EP.EmpPositionSepDate, EP.EmpSSN, EP.EmpAddress,
> EP.EmpOtherAddress, EP.EmpCity, EP.EmpState,
> EP.EmpZip, EP.EmpSepReason
> FROM EmpCore.dbo.tblEmployee E INNER JOIN
> EmpCore.dbo.tblPosition P ON E.PosID = P.PosID INNER
> JOIN
> EmpCore.dbo.tblCostCenter C ON P.PosCostCenter =
> C.CostCenterID INNER JOIN
> dbo.tblEmpInfo EF ON E.EmpID = EF.EmpID INNER JOIN
> EmpPersonal.dbo.tblEmpPersonalInfo EP ON E.EmpID =
> EP.EmpID
> WHERE (E.EmpActive = 1)
> ELSE
> SELECT E.EmpID, P.PosID, E.EmpFName, E.EmpMName, E.EmpLName,
> E.EmpSuffix, E.EmpShift, E.EmpStatus, E.EmpActive, P.PosRoleCode,
> P.PosTimeKeeper, C.CostCenter, EF.EmpSalary,
> EF.EmpDirectDeposit, EF.EmpInsID, EP.EmpRace, EP.EmpSex, EP.EmpDOB,
> EP.EmpStateBegDate,
> EP.EmpSWVTCBegDate, EP.EmpSWVTCSepDate,
> EP.EmpPositionBegDate, EP.EmpPositionSepDate, EP.EmpSSN, EP.EmpAddress,
> EP.EmpOtherAddress, EP.EmpCity, EP.EmpState,
> EP.EmpZip, EP.EmpSepReason
> FROM EmpCore.dbo.tblEmployee E INNER JOIN
> EmpCore.dbo.tblPosition P ON E.PosID = P.PosID INNER
> JOIN
> EmpCore.dbo.tblCostCenter C ON P.PosCostCenter =
> C.CostCenterID INNER JOIN
> dbo.tblEmpInfo EF ON E.EmpID = EF.EmpID INNER JOIN
> EmpPersonal.dbo.tblEmpPersonalInfo EP ON E.EmpID =
> EP.EmpID
> WHERE (E.EmpActive = 1) AND EP.EmpSSN = @EmpSSNEntry
> GO
>
> As you can see it takes the Social Security Number and filters the database
> with that value. I need to modify this SP to make it allow up to 10 SSN
> entries. How do I go about doing this? The problem is, there may be 10
> entries, and then there may only be 1 entry.
>
> Thanks,
> Drew Laing
>
>
>
- Next message: Hank: "how to convert 'if...else...' to CASE"
- Previous message: Alejandro Mesa: "RE: Log stored proc. errors to SQL log or Event Log"
- In reply to: Drew: "Stored Procedure with Multiple conditions"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|