Ideas???

  • So I can't seem to figure this out. In the table, the column is set up like,

    date_shipped(datetime,null)

    I am trying to run the following query below:

    --Query:

    --Pull all data with yesterday's ship date

    DECLARE @myDate DATE = convert(varchar(10),dateadd(day, -1, getdate()),112)

    SELECT *

    FROM [ThomasSci].[dbo].[tsi_gdserial_vw]

    where date_shipped = @myDate

    order by order_no desc, order_ext asc

    GO

    but no data seem to poulate.

    If i run:

    SELECT *

    FROM [ThomasSci].[dbo].[tsi_gdserial_vw]

    the output come out like so:

    2015-08-18 11:24:21.377

    What may be wrong?

  • Try this:

    declare @myDate datetime;

    set @myDate = cast(dateadd(day, -1, getdate()) as date);

    SELECT

    *

    FROM

    [ThomasSci].[dbo].[tsi_gdserial_vw]

    where

    cast(date_shipped as date) = @myDate

    order by

    order_no desc,

    order_ext asc

    GO

  • Or this:

    SELECT

    *

    FROM

    [ThomasSci].[dbo].[tsi_gdserial_vw]

    where

    date_shipped >= cast(dateadd(day, -1, getdate()) as date) and

    date_shipped < cast(getdate() as date)

    order by

    order_no desc,

    order_ext asc

    GO

  • worked like a charm. Thank you very much.

  • Or this:

    declare @myDate datetime;

    set @myDate = cast(dateadd(day, -1, getdate()) as date);

    SELECT *

    FROM [ThomasSci].[dbo].[tsi_gdserial_vw]

    where date_shipped >= @myDate

    AND date_shipped < DATEADD( dd, 1, @myDate)

    order by

    order_no desc,

    order_ext asc

    It's not a significant difference on what happens behind the scenes.

    EDIT: Didn't see that Lynn already posted this type of query.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 5 posts - 1 through 4 (of 4 total)

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