我有一個存儲過程,我將3個變量bankNumber
,branchNumber
和DateFrom
傳遞給。搜索存儲過程(SQL Server) - 從字符串轉換日期和/或時間時轉換失敗 - 簡單嗎?
基於這些變量,我想查詢表(在下面的圖片中看到的存儲過程)返回符合我傳遞的標準(通過變量)的所有記錄。當我通過它DateFrom
變量
Conversion failed when converting date and/or time from character string
這似乎是失敗的:
相反,我正在此錯誤。
謝謝您的幫助
ALTER PROCEDURE [dbo].[Search_Records]
@bankNumber varchar(3),
@branchNumber varchar(3),
@dateCreated datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE
@Bank_Number varchar(3) = @bankNumber,
@Branch_Number varchar(3) = @branchNumber,
@DateFrom datetime = @dateCreated,
@DateTo datetime = @dateCreated
SELECT DISTINCT
A.bankNumber,
A.branchNumber,
A.dateCreated
FROM
dbo.CENSORED A
WHERE
(@Branch_Number IS NULL OR bankNumber LIKE @BankNumber + '%')
AND (@Branch_Number IS NULL OR branchNumber LIKE @Branch_Number + '%')
AND (@DateFrom IS NULL OR dateCreated LIKE + @DateFrom + '%')
AND (@DateTo IS NULL OR dateCreated LIKE + @DateTo + '%')
END
你使用MySQL嗎?還是SQL Server?它們不是同一件事。 – 2014-10-29 19:26:03
@JohnConde sql server感謝您指出。 – 2014-10-29 19:26:27
'@DateFrom +'%''是什麼意思?匹配月份?匹配日?匹配年?匹配時間?.............. – 2014-10-29 19:31:26