| | |
Need help with SQL SELECT string
Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Thread Solved
![]() |
•
•
Join Date: Oct 2008
Posts: 2
Reputation:
Solved Threads: 0
I have been using the below SELECT string for some time and it has worked well, I now need to add a SUM and GROUP BY to this string and have not been able to get it to work.
Dim selstrHISTORY As String = "SELECT history.route_no,history.Acct_no,history.Post_date,history.tran_code," & _
"history.Amount,SUM(history.Amount),SERVICE.parcel FROM history INNER JOIN SERVICE ON service.serv_id = history.serv_id " & _
" WHERE history.route_no = 'PEN' AND history.post_date = " & "{" & DataGridViewDates.CurrentCell.Value.ToString & "}" & _
"AND history.tran_code = 'AC' GROUP BY history.Acct_no"
Need to add:
SUM(history.Amount)
GROUP BY history.Acc_no
Thanks for any help
Joe
Dim selstrHISTORY As String = "SELECT history.route_no,history.Acct_no,history.Post_date,history.tran_code," & _
"history.Amount,SUM(history.Amount),SERVICE.parcel FROM history INNER JOIN SERVICE ON service.serv_id = history.serv_id " & _
" WHERE history.route_no = 'PEN' AND history.post_date = " & "{" & DataGridViewDates.CurrentCell.Value.ToString & "}" & _
"AND history.tran_code = 'AC' GROUP BY history.Acct_no"
Need to add:
SUM(history.Amount)
GROUP BY history.Acc_no
Thanks for any help
Joe
When you make the query a Group By query, I believe you need to add that you are grouping by all the other fields as well, not just history.Acct_no.
If you don't want to group with the other fields, then either don't include them in the query or SUM them or perform some other calculation on them.
vb Syntax (Toggle Plain Text)
Dim selstrHISTORY As String = "SELECT history.route_no,history.Acct_no,history.Post_date,history.tran_code," & _ "history.Amount,SUM(history.Amount),SERVICE.parcel FROM history INNER JOIN SERVICE ON service.serv_id = history.serv_id " & _ " WHERE history.route_no = 'PEN' AND history.post_date = " & "{" & DataGridViewDates.CurrentCell.Value.ToString & "}" & _ "AND history.tran_code = 'AC' GROUP BY history.route_no, history.Acct_no, history.Post_date, history.tran_code, history.Amount, SERVICE.parcel"
If you don't want to group with the other fields, then either don't include them in the query or SUM them or perform some other calculation on them.
•
•
Join Date: Oct 2008
Posts: 2
Reputation:
Solved Threads: 0
Problem solved thanks to help from timothybard
Tim you pointed me in the right direction, actual string ends up as follows.
Thanks
Dim selstrHISTORY As String = "SELECT history.route_no,history.Acct_no,history.Post_date,history.tran_code," & _
"SUM(history.Amount),SERVICE.parcel FROM history INNER JOIN SERVICE ON service.serv_id = history.serv_id " & _
" WHERE history.route_no = 'PEN' AND history.post_date = " & "{" & DataGridViewDates.CurrentCell.Value.ToString & "}" & _
"AND history.tran_code = 'AC' GROUP BY history.route_no, history.Acct_no, history.Post_date, history.tran_code, SERVICE.parcel"
Tim you pointed me in the right direction, actual string ends up as follows.
Thanks
Dim selstrHISTORY As String = "SELECT history.route_no,history.Acct_no,history.Post_date,history.tran_code," & _
"SUM(history.Amount),SERVICE.parcel FROM history INNER JOIN SERVICE ON service.serv_id = history.serv_id " & _
" WHERE history.route_no = 'PEN' AND history.post_date = " & "{" & DataGridViewDates.CurrentCell.Value.ToString & "}" & _
"AND history.tran_code = 'AC' GROUP BY history.route_no, history.Acct_no, history.Post_date, history.tran_code, SERVICE.parcel"
![]() |
Similar Threads
- Urgent Help With a SQL Where statement (MS SQL)
- Results from Select statement differ in VB.NET and Access (VB.NET)
- sql query problem with MS Access and C# (C#)
- Generate sql string to query MySQL DB ? (PHP)
- Cast from type 'DBNull" to type 'String' is not valid (ASP.NET)
- Hi,Need help on sql select statement structure (MS SQL)
- select statemt LIKE (MySQL)
Other Threads in the VB.NET Forum
- Previous Thread: Crystal reports and vb
- Next Thread: anobody hlp...Scrollbar on form
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account application array basic beginner browser button buttons center check click code combo crystalreport cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist excel exists fade file-dialog filter forms ftp generatetags hardcopy html images input insert intel listview module monitor net networking number open output panel passingparameters picturebox picturebox2 port print printing problem project regex right-to-left searchvb.net select serial settings shutdown socket sqldatbase sqlserver survey tcp temperature text textbox timespan toolbox transparency trim txttoxmlconverter user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





