Hi all,
I have a scenario where I would like to retrieve a record from EMPLOYEE table based on our end users enter the EXACT Date of Birth or just a partial Date of Birth.
I am able to retrieve a record when our end users enter the EXACT DOB (09-15-1960) but when our end users enter a partial DOB (just "YYYY" 1960), then I don't have any records returned.
The following is my WHERE clause:
note: vp.DOB is DATETIME field.
DECLARE @DOB DATETIME DECLARE @DOB_YYYY DATETIME DECLARE @DOB_MM DATETIME DECLARE @DOB_DD DATETIME SET @DOB = NULL SET @DOB_YYYY = '1960' SET @DOB_MM = NULL SET @DOB_DD = NULL SELECT DISTINCT TOP (5000) dbo.fnGetDisplayName(vp.LastOrBusinessName,vp.FirstName, vp.MiddleName, vp.SuffixName) as [Name], dbo.fnGetDisplayNameByPartyID(vp.FirstPlaintiffID) as Plaintiff FROM tblEmployee vp WITH (NOLOCK) WHERE -- Search by DOB (vp.DOB = @DOB OR @DOB IS NULL) AND ((SELECT YEAR(vp.DOB)) = @DOB_YYYY)
Any help is greatly appreciate it.
THANK YOU!