August 19, 2015 at 11:11 am
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?
August 19, 2015 at 11:18 am
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
August 19, 2015 at 11:21 am
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
August 19, 2015 at 11:23 am
worked like a charm. Thank you very much.
August 19, 2015 at 11:23 am
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.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply