Query in SQL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to create a query using SQL and keep getting syntax errors, can
anyong point me in the correct direction? Here is my code:

SELECT [member_id1] & [member_id2] AS [key],
SUM(CASE WHEN test.category_nbr = 1 THEN test.SalesDollars ELSE 0 END)
AS SalesDollarsCat1 ,
FROM test
GROUP BY [key];

So, basically I have a table called "test", and I want to sum up the Sales
Dollars for each separate category_nbr, and group by key. I have around 100
category numbers so once I get the first line working I can just copy paste
for all other's.

Thanks,
 
David said:
I'm trying to create a query using SQL and keep getting syntax
errors, can anyong point me in the correct direction? Here is my
code:

SELECT [member_id1] & [member_id2] AS [key],
SUM(CASE WHEN test.category_nbr = 1 THEN test.SalesDollars ELSE
0 END) AS SalesDollarsCat1 ,
FROM test
GROUP BY [key];

So, basically I have a table called "test", and I want to sum up the
Sales Dollars for each separate category_nbr, and group by key. I
have around 100 category numbers so once I get the first line working
I can just copy paste for all other's.

Thanks,

Is this a plain vanilla local query and not a passthrough query? Access SQL
does not support the Case function. You have to substitute either IIf(),
Switch(), or a user defined function instead.
 
Back
Top