Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
cmd.CommandText = "select facno,max(fdate) as fdate,fbalance from MAINTRAN wheere fdate<='" & Format(prdate, "yyyy/MM/dd") & "' GROUP BY facno "
Posted
Comments
/\jmot 25-Nov-14 4:18am    
not clear.
be more specific.
Sinisa Hajnal 25-Nov-14 4:25am    
What do you need to do? What is the problem?
Tomas Takac 25-Nov-14 4:48am    
My guess is it fails because fbalance is neither aggregate nor in group by. What you most probably want is a sum: sum(fbalance) as totalfbalance
lakshjoshi 25-Nov-14 6:14am    
yes it is thanks for reply you saved lots of time,i am working on this 2 days...where are you man before 2 days...:)..thanks here goes my working query....
"select facno,max(fdate) as fdate ,max(fbalance) as fbalance from MAINTRAN where MAINTRAN.fbankcode='" & "010" & "'" & _
"and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _
"and MAINTRAN.fbranchcode='" & "01" & "' group by facno"
Shweta N Mishra 25-Nov-14 5:21am    
You are asking same question again and again why dont you clear it out in one thread only, It Makes other to rework same solution for you again and again.

There are a couple of things here: there is the fbalance problem mentioned by Tomas Takac in the comments above, the spelling of "wheere", and the use of concatenation.

Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. This is a safe use, but if you are doing it here, the chances are you do it elsewhere and leave your database wide open to attack.
Try this:
VB
cmd.CommandText = "SELECT facno, MAX(fdate) AS fdate, SUM(fbalance) AS totalfbalance FROM MainTran WHERE fdate<=@DT GROUP BY facno"
cmd.Parameters.AddWithValue("@DT", prdate.Date)
 
Share this answer
 
Comments
lakshjoshi 25-Nov-14 5:50am    
if i want latest fbalance then...?
lakshjoshi 25-Nov-14 6:52am    
thanks my code works...thank you...
OriginalGriff 25-Nov-14 7:28am    
You're welcome!
thanks its works ...closing cermany:here my working query:----

SQL
"select facno,max(fdate) as fdate ,max(fbalance) as fbalance from MAINTRAN where MAINTRAN.fbankcode='" & "010" & "'" & _
                                          "and MAINTRAN.fdate<='" & Format(prdate, "MM/dd/yyyy") & "' " & _
                                          "and MAINTRAN.fbranchcode='" & "01" & "' group by facno"


thank god its works.....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900