how to find last enry in table using sql query need help

Nov 27 2014 2:20 AM
cmd.CommandText = "SELECT  distinct GLMAST.fglhead,MAINFILE.facno,max(MAINTRAN.fdate) as fdate ,max(MAINTRAN.fbalance) as fbalance  FROM MAINTRAN INNER JOIN MAINFILE ON  MAINFILE.facno like MAINTRAN.facno INNER JOIN MASTERID ON  MAINFILE.fmasterno like MASTERID.fmasterid  INNER JOIN  GLMAST ON GLMAST.fglcode like  LEFT(MAINFILE.facno,9) and   GLMAST.fglhead = '" & ComboBox2.Text & "' and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _                                           "where MAINTRAN.fbankcode='" & "010" & "'" & _                                          "and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _                                          "and MAINTRAN.fbranchcode='" & "01" & "' group by MAINFILE.facno,GLMAST.fglhead "
Collapse | Copy Code
 
With cmd
dr = .ExecuteReader
End With

If dr.HasRows = True Then
Do While dr.Read
presentdaybal = dr!fbalance
Loop
dr.Close()

Answers (3)