# Subtract data from the first day vs. the last day of the month in SQL of all months of the year

**URL:** <https://forum.inductiveautomation.com/t/subtract-data-from-the-first-day-vs-the-last-day-of-the-month-in-sql-of-all-months-of-the-year/85757>\
**Category:** Ignition\
**Tags:** ignition79, database, vision\
**Created:** [February 15, 2024, 2:45pm UTC](https://forum.inductiveautomation.com/t/subtract-data-from-the-first-day-vs-the-last-day-of-the-month-in-sql-of-all-months-of-the-year/85757 "2024-02-15T14:45:47Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 15, 2024, 2:52pm UTC](https://forum.inductiveautomation.com/t/subtract-data-from-the-first-day-vs-the-last-day-of-the-month-in-sql-of-all-months-of-the-year/85757/2 "2024-02-15T14:52:35Z")

</div>

This is a duplicate of what you asked two days ago. Keep discussions in one topic, per [this forum's rules](https://forum.inductiveautomation.com/faq).

> [@Compare start of month data and end of month data](https://forum.inductiveautomation.com/t/compare-start-of-month-data-and-end-of-month-data/85598):
>
> HI I have a currently query for compares a previous day against a current day, but now I need to compare the start day of the month against the last day of the month. this my currently query: DECLARE @FechaInicial DATE = '2024-01-08'; DECLARE @FechaFinal DATE = '2024-02-08'; SELECT dm.Fecha, SUM(CASE WHEN dm.Linea = 'ELFO\_006\_Oficinas' THEN dm.Dato - ISNULL( dp.Dato, 0) ELSE 0 END) AS ELFO\_006\_Oficinas\_Diferencia, SUM(CASE WHEN dm.Linea = 'ELFO\_007\_Rim' THEN dm.Dato - ISNULL( …

---

_[View the full topic](https://forum.inductiveautomation.com/t/subtract-data-from-the-first-day-vs-the-last-day-of-the-month-in-sql-of-all-months-of-the-year/85757)._
