Hi, all,
I am a little confused and not sure what is going on, so would like your input.
I have two DateTimePickers. One for Date From and another for Date To, to search for records based on a date range.
If I specify a date range from 1/1/2014 to 2/22/2014, two records should appear, but only one does.
I am using a PROC and also formatting the date for the parameter to yyyy-mm-dd. Maybe this is the issue?
Screen shots and code attached.
PROC:Code:If Not SearchDateFrom.Enabled = False _ And Not SearchDateTo.Enabled = False Then .Parameters.Add("@DateFrom", SqlDbType.DateTime).Value = Format(DateTime.Parse(SearchDateFrom.Text), "yyyy-MM-dd") .Parameters.Add("@DateTo", SqlDbType.DateTime).Value = Format(DateTime.Parse(SearchDateTo.Text), "yyyy-MM-dd") Else .Parameters.Add("@DateFrom", SqlDbType.DateTime).Value = DBNull.Value .Parameters.Add("@DateTo", SqlDbType.DateTime).Value = DBNull.Value End If
As you can see from the screen shots, based on the date range, it should return two rows, but it only returns one. Any ideas?Code:ALTER PROCEDURE [dbo].[SP_ObtainTicketInformation] @TicketNumber AS INT, @RMANumber AS INT, @StoreNumber AS INT, @TicketStatus AS VARCHAR(16), @CreatedBy AS VARCHAR(250), @DateFrom AS DATETIME, @DateTo AS DATETIME, @KeywordSearch AS VARCHAR(MAX) AS SET NOCOUNT ON BEGIN SELECT T.TicketID AS TktNo, T.StoreNumber AS StoreNo, T.RMANumber AS RMANo, T.DateCreated, T.IssueDescription, T.StepsToResolve, T.TicketStatus, T.CreatedBy, T.DateLastModified, T.LastModifiedBy, T.DateResolved FROM [TICKETMANAGER].[dbo].[Tickets] AS T WHERE T.TicketID = @TicketNumber OR T.RMANumber = @RMANumber OR T.StoreNumber = @StoreNumber OR T.TicketStatus = @TicketStatus OR T.CreatedBy = @CreatedBy OR T.DateCreated BETWEEN @DateFrom AND @DateTo AND T.DateResolved IS NOT NULL OR T.IssueDescription LIKE '%' + @KeywordSearch + '%' OR T.StepsToResolve LIKE '%' + @KeywordSearch + '%' END
![]()




Reply With Quote