tnnelzo (6/20/2013)
It is always from the first day of the current month....to the current dayand b.date_entered >=cast('2013-06-01 00:00:00.000' as datetime)
and b.date_entered < cast('2013-06-20 00:00:00.000'as datetime)
and when the month ends it changes to
and b.date_entered >=cast('2013-06-01 00:00:00.000' as datetime)
and b.date_entered <=cast('2013-06-30 00:00:00.000'as datetime)
Thanks and Best Regards.
so you just need to get used to the DATEADD /DATEDIFF functions,a s they are very powerful;
this is what i think you are after; note i changed your join to be explicit, and aliased your columns :
SELECT
DAY(b.date_entered) AS Day_D,
SUM(a.despatched_qty) AS DesQty,
SUM(a.val) AS Val
FROM scheme.dgtable1 a
INNER JOIN scheme.dntable3 b
ON a.order_no = b.order_no
WHERE a.product LIKE 'Machines%'
AND b.date_entered >=DATEADD(mm, DATEDIFF(mm,0,GETDATE()), 0) --first day of THIS month
AND b.date_entered < DATEADD(dd, DATEDIFF(dd,0,GETDATE()), 1) --midnight of tomorrow morning
GROUP BY DAY(b.date_entered)
ORDER BY DAY(b.date_entered)
Lowell