Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 Get 2nd last date from db

Author  Topic 

Braddy
Starting Member

3 Posts

Posted - 2010-06-01 : 17:29:38
Hi all

I have 3 tables and need info from them all, e.g I have a table called PriceTable and from this table I need the price. I have an InvoiceTable and in here I store my last invoice date. I have a CarTable from which I select the car I invoice. Only the carTable and the invoiceTable is related to each other.
It works like this, I select a car (renting parking space) and I choose a date and save. This date is my invoice date, next month I'll choose the same car and invoice it again. My issue is when I need to print the invoice, I set the date same as the invoice date and a datareader will give me all cars invoiced on that date. But I need the datediff between last invoice and this invoice that will tell me how many days has passed since the last invoice...Example, last invoice 2010-05-01 and this time I invoice 2010-06-01, then I would set the date to 2010-06-01 and I'ld need a sql statement that find all cars on this date and also find out that the last invoice date was 2010-05-01 and gives me the datediff.
Is it possible, thank you in advance!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-02 : 03:40:56
SELECT MAX(InvoiceDate) FROM Table WHERE InvoiceDate < '20100601'


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -