zimmer9
asked on
I am using SQL Server 2008. Is there a way to pass in 2 parameters strings in the format MM/DD/YYYY and convert these strings into a DATE data type using SQL Server 2008 and then make a date compare?
I am using SQL Server 2008. Is there a way to pass in 2 parameters strings in the format MM/DD/YYYY and convert these strings into a date data type using SQL Server 2008 and then make a date comparison. I don't know if casting would help.
I tried the following execute statement on the stored procedure below:
exec proc_CSL_UndeliverableByDa te '03/07/2003', '03/07/2003'
but no records are returned in the result set although I know there are records with a value in the "dtCreated" field
of '2003-03-07'.
USE [CSL]
GO
/****** Object: StoredProcedure [dbo].[proc_CSL_Undelivera bleByDate] Script Date: 01/12/2017 20:11:48 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[proc_CSL_Undelivera bleByDate] @strbegdate nvarchar(10) , @strenddate nvarchar(10) AS
DECLARE @startDate DATETIME
DECLARE @endDate DATETIME
SELECT @startDate = CONVERT(DATETIME, @strbegdate, 101)
SELECT @endDate = CONVERT(DATETIME, @strenddate, 101)
SELECT bank As Bank, CONVERT(VARCHAR,[chkDt],10 1) As 'Check Date', branch as Branch, chkNum AS 'Check Number',
accountNum AS 'Account Number', amount AS Amount, CONVERT(VARCHAR,[dtCreated ],101) AS 'Journal Date'
FROM tbl_CSL_UndeliverableCheck s
WHERE dtCreated >= @startDate AND dtCreated < @endDate
GROUP BY tbl_CSL_UndeliverableCheck s.bank, ([dtCreated]), [chkDt], [branch], [chkNum], [accountNum], [amount];
I tried the following execute statement on the stored procedure below:
exec proc_CSL_UndeliverableByDa
but no records are returned in the result set although I know there are records with a value in the "dtCreated" field
of '2003-03-07'.
USE [CSL]
GO
/****** Object: StoredProcedure [dbo].[proc_CSL_Undelivera
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[proc_CSL_Undelivera
DECLARE @startDate DATETIME
DECLARE @endDate DATETIME
SELECT @startDate = CONVERT(DATETIME, @strbegdate, 101)
SELECT @endDate = CONVERT(DATETIME, @strenddate, 101)
SELECT bank As Bank, CONVERT(VARCHAR,[chkDt],10
accountNum AS 'Account Number', amount AS Amount, CONVERT(VARCHAR,[dtCreated
FROM tbl_CSL_UndeliverableCheck
WHERE dtCreated >= @startDate AND dtCreated < @endDate
GROUP BY tbl_CSL_UndeliverableCheck
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please try this..
You have to use YYYY-MM-dd format..
Open in new window
Hope it helps!