SQLTeam.com | Weblogs | Forums

Help with a SQL query


I'm new at this and need the help of the experts, im trying to make a query using the following;


FIELDS: cus_name, cus_id, pur_date, sales_type, sales_total,
Make a query to export the fields above listing only when pur_date is between 1/1/16 – 1/31/16. Also
Sales_type stores 2 different characters “a” and “b” . Can these be put in 2 different columns suming the sales_total of each?


This sounds like homework or something similar. If so, we can only offer guidelines, not do the work for you.

Use a WHERE clause to restrict the range of dates selected.

The Sales_Type totals are trickier -- usually it's easiest to use CASE to do that. Are you familiar with CASE clauses?


Hi, thanks for your prompt reply.

Im not in school, i'm trying to learn this by my own, I'm not familiar with CASE. any help that can put me on the right direction will help.



CASE has 2 forms:

Simple CASE expression:   
CASE input_expression   
     WHEN when_expression THEN result_expression [ ...n ]   
     [ ELSE else_result_expression ]   
Searched CASE expression:  
     WHEN Boolean_expression THEN result_expression [ ...n ]   
     [ ELSE else_result_expression ]   



Hi thanks joetorre,

This won't work from Visual fox pro 9 right?
this is what I have so far;

Select custable1.cus_name, custable1.cus_id, custable1.pur_date, custable1.sales_type, custable1.sales_total;
from custable1 where custable1.pur_date > date(2016,01,01) and custable1.pur_date < date(2016,01,31);
into cursor temp1

I can't figure out how to filter the custable1.sales_type and also sum the sales_total either.


Please note that this is a Microsoft SQL Server forum.