Results 1 to 5 of 5

Thread: Modification Needed

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    14

    Modification Needed

    Hello Everybody

    I use these code but this returns following error message

    Incorrect syntax near the keyword 'group'.


    Code:
    str = "Select c,acccode,acc_name,title,Count(vou_no)As vou_no,vou_no As balance,	sum(qty*weight) As weight,Sum(qty)As qty from gpass	order By acccode group By acccode where Date between '" & Me.first_date.Text & "' and  '" & Me.last_date.Text & "'"
            dt = GetTable(str)
    What is wrong, please modify

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Modification Needed

    GROUP BY should come before ORDER BY
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Modification Needed

    In SQL statements, the WHERE condition comes before the GROUP BY condition
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    14

    Re: Modification Needed

    Now I have wrote codes as

    Code:
      str = "Select c,acccode,tittle,Count(vou_no)As vou_no,vou_no As balance,sum(qty*weight) As weight,Sum(qty)As qty from gpass where Date between '" & Me.first_date.Text & "' and  '" & Me.last_date.Text & "' group By acccode order By acccode"
            dt = GetTable(str)
    but it shows this error message

    Code:
    Column 'gpass.c' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
    The datatype of column c is char(1)

    Please help

  5. #5
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Modification Needed

    you should add it to the group by (and all the other columns)
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width