(I initially had this on the SQL forumns but they are telling me I need to post here as it's SQL through VB6)
I'm running the following query through the visual basic 6 data designer against a SQL 2005 database.
SELECT `Part No`, SUM(Val - `Cost Of Sale`) AS Margin, Description,
`Product Group`
FROM tblSales
WHERE (`Invoice Date` BETWEEN (# 01 / 01 / 2006 #) AND
(# 01 / 02 / 2007 #))
GROUP BY `Part No`, Description, `Product Group`
ORDER BY SUM(Val - `Cost Of Sale`) DESC
This works OK apart from the sort order. It lists margins of "0" first, then "- numbers" and then the order is correct, i.e. largest positive number followed by the next largest and so on.
i.e. 0, 0, 0, -14, 590, 570, 300, 200, etc.
I want to be able to display so that largest positive number followed by the next largest number are at the top, eventually going to 0 and then eventuially listing the - numbers.
i.e. 590, 570, 300, 200, 0, 0, 0, -14.
I'm presuming this isn't happening now because maybe the margin field isn't numeric?
I've tried to use a CONVERT statement but get errors. Is there another way to convert the calculated margin field to numeric so I can order the column descending?
Thanks
I'm running the following query through the visual basic 6 data designer against a SQL 2005 database.
SELECT `Part No`, SUM(Val - `Cost Of Sale`) AS Margin, Description,
`Product Group`
FROM tblSales
WHERE (`Invoice Date` BETWEEN (# 01 / 01 / 2006 #) AND
(# 01 / 02 / 2007 #))
GROUP BY `Part No`, Description, `Product Group`
ORDER BY SUM(Val - `Cost Of Sale`) DESC
This works OK apart from the sort order. It lists margins of "0" first, then "- numbers" and then the order is correct, i.e. largest positive number followed by the next largest and so on.
i.e. 0, 0, 0, -14, 590, 570, 300, 200, etc.
I want to be able to display so that largest positive number followed by the next largest number are at the top, eventually going to 0 and then eventuially listing the - numbers.
i.e. 590, 570, 300, 200, 0, 0, 0, -14.
I'm presuming this isn't happening now because maybe the margin field isn't numeric?
I've tried to use a CONVERT statement but get errors. Is there another way to convert the calculated margin field to numeric so I can order the column descending?
Thanks