|
-
Feb 22nd, 2014, 09:51 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Pulling records from database based on date from DateTimePicker issue.
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.
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
PROC:
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
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?

Last edited by BrailleSchool; Feb 22nd, 2014 at 09:52 AM.
Reason: Added PROC
-
Feb 22nd, 2014, 09:54 AM
#2
Thread Starter
PowerPoster
Re: Pulling records from database based on date from DateTimePicker issue.
Ok. I figured it out as I posted.
The PROC had to be modified to remove the AND T.DateResolved IS NOT NULL
Last edited by BrailleSchool; Feb 22nd, 2014 at 09:57 AM.
Reason: Added output screen shot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|