SQL Query not running...

  • Try this statement

    select * from tbldeals

    --where trade_date = '2009-03-06 00:00:00'

    where convert(datetime,(convert(int,trade_date,101)))= '2009-03-06 00:00:00'

    ARUN SAS

  • And why not do this instead:

    DECLARE @ld_TestDate datetime

    SET @ld_TestDate = CONVERT(datetime, '2009-03-06 00:00:00')

    SELECT * FROM tbldeals

    WHERE trade_date >= @ld_TestDate

    AND trade_date < @ld_TestDate + 1

    i.e. do the conversion ONCE and allow the server to use the index (if any) on column trade_date

  • Nice it would be if feedback OP would provide.

  • Lynn Pettis (3/11/2009)


    Nice it would be if feedback OP would provide.

    Hee! True. @=)

    Everytime I run into this issue, it's because I'm either using an = sign with a date comparison when there's a time attached (IE, Mydate = '01/01/2009' when the datetime is 2009-01-01 23:52:00) or when the field is not a true datetime column / I'm using the wrong datetime format for my search.

    But, until we hear back from the OP, we will never know if any of our suggestions worked.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Just a simple attempt...

    If you execute the following script. Do you see the milliseconds? Maybe your SSMS does not show them in its output. Do you use grid or text output?

    ;WITH test (id, dt) AS

    (

    SELECT 1, GETDATE()

    UNION ALL SELECT 2, '2009-03-19T12:34:56.787'

    )

    SELECT * FROM test

    Greets

    Flo

Viewing 5 posts - 16 through 19 (of 19 total)

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