SQL Server Performance

sql server dateime issue

Discussion in 'ALL SQL SERVER QUESTIONS' started by Wendy elizabeth, Sep 29, 2012.

  1. Wendy elizabeth New Member

    In a sql server 2008 r2 database, I have a question about using a datetime field.
    I have a column called start_date that is setup in the database as a datetime column.
    I want to setup a parameter in a stored procedure that will select the date I pick.
    Right now I have the parameter setup like the following:
    @Start_Date datetime = NULL.
    when I pass a value like 01/17/2012 in the @Start_Date paramter, no records are selected.
    However I know there are records where the start_date in the database = 01/17/2012.
    It is probably due to the time part of the datetime value.
    Thus can you tell me what I can do to pass the value of 01/17/2012 to the stored procedure and/or
    tell me what exact value I should pass to the stored procedure so the records I want are selected?
  2. Hrishi_nk New Member

    The most simplest thing you could do is declare a variable @end_date , set it to next day

    DECLARE @end_date DATETIME
    SET @end_date= @start_date+1

    and write your where clause as below

    WHERE start_date >=@start_date and start_date<@end_Date

    The above query will return you all the records for a particular date you pass in @start_date
  3. Shehap MVP, MCTS, MCITP SQL Server

    As per my understanding , you are trying to use single parameter for your date searches that can be applicable if you use the below where clause :

    Wheredatediff(D,Start_date,@Start_Date)=0

    Kindly work out it and let me know you your feedback

Share This Page