下面是我的存储过程。
USE [CBRDev]
GO
/****** Object: StoredProcedure [dbo].[usp_ExportData] Script Date: 6/14/2017 12:48:44 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[usp_ExportData]
(
@StartDate Date,
@EndDate Date
)
AS
BEGIN
Select REPLACE(U.EmployeeID, ',','') as EmployeeID,REPLACE(U.ClientID, ',','') as ClientID,REPLACE(U.ID, ',','') as ID,
REPLACE(U.FirstName, ',','')as FirstName,REPLACE(U.MiddleName, ',','')as MiddleName,
REPLACE(U.LastName, ',','')as LastName,REPLACE(U.Email, ',','')as Email,REPLACE(U.SSN, ',','')as SSN,
REPLACE(U.DateOfBirth, ',','')as DateOfBirth,REPLACE(U.Gender, ',','')as Gender,REPLACE(U.CreatedDate, ',','')as CreatedDate,
REPLACE(U.ModifiedDate, ',','')as ModifiedDate, REPLACE(UPI.StreetAddress1, ',','')as StreetAddress1,
REPLACE(UPI.StreetAddress2, ',','')as StreetAddress2,REPLACE(UPI.City, ',','')as City,
REPLACE(UPI.State, ',','')as State,
REPLACE(UPI.ZipCode, ',','')as ZipCode,
REPLACE(UPI.CellPhoneNumber, ',','')as CellPhoneNumber, '' as Department, '' as JobTitle, '' as StreetAddress3 from Users U INNER JOIN PersonalContacts UPI ON U.ID= UPI.UserID
where U.ModifiedDate >=@StartDate and U.ModifiedDate<= @EndDate
END
其中如果@StartDate 和@EndDate 参数为空,那么我想删除where 条件。
如果存在 @StartDate 和 @EndDate 参数,则应用 where 条件,那么我该怎么做?