以下は私のストアドプロシージャです。使用方法SQLのwhere句のelse節
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 >[email protected] and U.ModifiedDate<= @EndDate
END
@StartDateパラメータと@EndDateパラメータがnullの場合、where条件を削除します。
@StartDateと@EndDateパラメータが存在する場合は、どこに条件を適用しますか?どのようにすればいいですか?
開始日がある場合は終了日を、そうでなければ日付はないはずですか? – maSTAShuFu