Results 1 to 2 of 2

Thread: [RESOLVED] Pulling records from database based on date from DateTimePicker issue.

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [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?
    Name:  rows.jpg
Views: 234
Size:  46.3 KB
    Name:  view.jpg
Views: 259
Size:  100.0 KB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width