tags:

views:

68

answers:

4

I am going to be crazy I think. Please Help.

I have a table which fields are Date, No, Turnover, TotalWin, Opencredit, Handpay, Billin, gamesplayed and I am trying to write sql in vb.net that will show me previous day value but I cant. Here is what I am trying to do.

SELECT Meter.* 
FROM 
  Meter AS Previous, 
  Turnover As Prev_turnover  
WHERE Date = '
  SELECT Max(Date) 
  FROM Meter AS Previous2
  WHERE Previous2.Date < Date 
  AND Previous2.No = ‘No' 
  AND Previous.No = ‘No’ 

What is wrong in where I am doing mistake I really don't know. If anyone help will be appreciated.

Thanks

+1  A: 

What specific problem are you having? Is it returning the wrong value or just giving you an error?

I'm guessing that you just need to get the prior days date. If that is the case in SQL Server you can use the DATEADD function like this: select DATEADD(day, -1, date). You could also use that in a where clause or a join clause.

fande455
Ok I am getting closer I think. I am getting error : (The Microsoft Jet database engine cannot find the input table or query 'Turnover;. Make sure it exists and that its name spelled correctly.) by this codeSELECT [Date], [No], Turnover, TotalWin, GamesPlayed, CreditIn, BillIn, HandPayFROM Meter Previous,Turnover As Prev_turnover WHERE [Date] = 'SELECT Max([Date]) FROM Meter As Previous2 WHERE Previous2.[Date]<[Date] AND Previous.[No]=[No]'
Hakan
A: 

Ok Thomas I am not able to give correct answer to your question because first time in my Life I am trying to write sql. I was doing this with MSAccess and it was easy. Now I am getting pretty simple error I think with this code but I can't find solution again. What is wrong.

SELECT [Date], [No], Turnover, TotalWin, GamesPlayed, CreditIn, BillIn, HandPay FROM Meter As Previous, Turnover As Prev_turnover WHERE [Date] = 'SELECT Max([Date]) FROM Meter As Previous2 WHERE Previous2.[Date]<[Date] AND Previous.[No]=[No]'

Hakan
First says "Cannot convert entry to valid date/time; TO_DATE function might be required." then in next execution says "The Microsoft Jet database engine cannot find the input table or query 'Turnover;. Make sure it exists and that its name spelled correctly."
Hakan
A: 
Hakan
SELECT Meter.[Date], Meter.[No], Meter.Turnover, Meter.TotalWin, Meter.GamesPlayed, Meter.CreditIn, Meter.BillIn, Meter.HandPayFROM Meter As Previous,Turnover As Prev_turnover WHERE Meter.[Date] = 'SELECT Max(Meter.[Date]) FROM Meter As Previous2 WHERE Previous2.[Date]<Meter.[Date] AND Previous.[No]=Meter.[No]'
Hakan
A: 

I found answer

SELECT     Date, No, Turnover, [Total Win], [Games Played], [Credit In], [Bill In], [Hand Pay]

FROM tblMeter WHERE (Date >= DATEADD(day, DATEDIFF(day, 1, GETDATE()), 0)) AND (Date < DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0))

Thaks to everyone who try to help me.

Hakan