Subject Re: [firebird-support] Help on this SQL statment
Author Alexandre Benson Smith
Em 15/6/2013 16:54, Iwan Cahyadi Sugeng escreveu:
> Change it into this syntax:
>
> SQLCommand = vbNullString
>
> SQLCommand = SQLCommand & "SELECT "
>
> SQLCommand = SQLCommand & "PRODUCTCODE,"
>
> SQLCommand = SQLCommand & "PRODUCTDESCRIPTION,"
>
> SQLCommand = SQLCommand & "SUM(PRODUCTQTY),"
>
> SQLCommand = SQLCommand & "SUM(PRODUCTTOTAL) "
>
> SQLCommand = SQLCommand & "From ProductHistory "
>
> SQLCommand = SQLCommand & "WHERE PRODUCTDATE Between '" & StartDate & "'
> AND '" & EndDate & "' "
>
> SQLCommand = SQLCommand & "GROUP BY PRODUCTODE, PRODUCTDESCRIPTION "
>
> SQLCommand = SQLCommand & "ORDER BY PRODUCTQTY DESC "
>
> SQLCommand = SQLCommand & "ROWS 1 TO 25"
>
>
>

The error will be corrected by the addition of ProductCode to the GROUP
BY clause, as the others have said, but I think the ORDER clause should be:

SQLCommand = SQLCommand & "ORDER BY 3 DESC "


That way the result would be order by the Sum of ProductQty

see you !