Hello, I have a sql 2008r2 view that shows Me the invoices on db and I need to show just the last six months of a customers, I'm not talking about the last six months of the year, I'm talking about the last 6 months of the invoices that a customer haves, this is the code I have :
CODE :
SELECT faknr AS InvoiceNr, fakdat AS InvoiceDate, YEAR(fakdat) AS YearNr, MONTH(fakdat) AS MonthNr, dagbknr AS InvoiceType, debnr AS DebtorNr, inv_debtor_name AS DebtorName
FROM dbo.frhkrg WITH (NOLOCK)
RESULT :
| InvoiceNr | InvoiceDate | YearNr | MonthNr | InvoiceType | DebtorNr| DebtorName |
| 1348 | 2012-11-10 | 2012 | 11 | 132 | 1005 | Deb1005 |
| 1622 | 2012-12-23 | 2012 | 12 | 132 | 1005 | Deb1005 |
| 1821 | 2016-01-25 | 2016 | 01 | 132 | 1005 | Deb1005 |
| 1923 | 2016-02-10 | 2016 | 02 | 132 | 1005 | Deb1005 |
| 2049 | 2016-03-25 | 2016 | 03 | 132 | 1005 | Deb1005 |
| 2223 | 2016-04-10 | 2016 | 04 | 132 | 1005 | Deb1005 |
| 2305 | 2016-05-25 | 2016 | 05 | 132 | 1005 | Deb1005 |
| 2322 | 2016-05-29 | 2016 | 05 | 132 | 1005 | Deb1005 |
In this particular case the last six months will be :
| InvoiceNr | InvoiceDate | YearNr | MonthNr | InvoiceType | DebtorNr| DebtorName |
| 1622 | 2012-12-23 | 2012 | 12 | 132 | 1005 | Deb1005 |
| 1821 | 2016-01-25 | 2016 | 01 | 132 | 1005 | Deb1005 |
| 1923 | 2016-02-10 | 2016 | 02 | 132 | 1005 | Deb1005 |
| 2049 | 2016-03-25 | 2016 | 03 | 132 | 1005 | Deb1005 |
| 2223 | 2016-04-10 | 2016 | 04 | 132 | 1005 | Deb1005 |
| 2305 | 2016-05-25 | 2016 | 05 | 132 | 1005 | Deb1005 |
| 2322 | 2016-05-29 | 2016 | 05 | 132 | 1005 | Deb1005 |
Thanks in advance...