date issues

  • SELECT

    *

    FROM Table1

    WHERE

    mydate =convert(varchar, getdate(), 111)

    I am running this query in SSIS.I have data with todays date but I cant return the data with the above sql.It runs good in sql analyser but does not return data in SSIS.There are no errors when I run the SSIS package.The package creates a text file as output.Appreciate reponses.

  • This was removed by the editor as SPAM

  • sqlserver12345 (6/10/2010)


    SELECT

    *

    FROM Table1

    WHERE

    mydate =convert(varchar, getdate(), 111)

    I am running this query in SSIS.I have data with todays date but I cant return the data with the above sql.It runs good in sql analyser but does not return data in SSIS.There are no errors when I run the SSIS package.The package creates a text file as output.Appreciate reponses.

    Does the 'mydate' column contain time? Or, does it only have the date with 00:00:00.000 for the time? Is it actually defined as a datetime data type?

    Generally, it is better to query dates using an open-interval range instead of equal or between. For example:

    DECLARE @startDate datetime;

    DECLARE @endDate datetime;

    SET @startDate = DATEADD(day, DATEDIFF(day, 0, getdate()), 0); -- midnight today

    SET @endDate = DATEADD(day, 1, @startDate); -- tomorrow at midnight

    SELECT ...

    FROM dbo.Table1

    WHERE MyDate >= @startDate

    AND MyDate < @endDate;

    The above will include everything for today, however - I would not be querying for everything today since the day is not finished yet. I would be querying for everything yesterday.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply