David writes "I have a question, I have seen your posting and I guess I am asking for helpWhat I need is to get the total COUNT on the sales rep, with using the (postal code) I am using substring to extract the first 3 Like substring(postalcode,1,3) but I am running in to problems, the count is returning a very high number.. Our postal code in Canada is like this L8K 2W3 I only need the L8K. I can count that, but when I have to match it with a salesrep I am getting screwed up.As you can tell I am JR. But trying hard. I have also used outter joins to make it work but this seems to be working...well maybe not...I am dealing with 3 tables here there are.SALES1 SALES_ID numeric 5 00 Salesrep_ID numeric 5 00 BU_ID numeric 5 00 Customer_ID numeric 5 00 [YEAR] int 4 -10 PERIOD1 numeric 5 10 PERIOD2 numeric 5 10 PERIOD3 numeric 5 10 PERIOD4 numeric 5 10 PERIOD5 numeric 5 10 PERIOD6 numeric 5 10 PERIOD7 numeric 5 10 PERIOD8 numeric 5 10 PERIOD9 numeric 5 10 PERIOD10 numeric 5 10 PERIOD11 numeric 5 10 PERIOD12 numeric 5 10 COMMENT varchar 255 10 CURR_Salesrep_ID numeric 5 10 CURR_BU_ID numeric 5 1CUSTOMER3 CUSTOMER_ID numeric 9 00 BU_ID numeric 9 10 SALESREP_ID numeric 9 10 CUSTNO varchar 6 10 CUST_TYPE_ID numeric 9 10 COMPANY varchar 50 10 POSTALCODE varchar 10 10 BILL_ACCT varchar 8 10 ADDRESS1 varchar 35 10 ADDRESS2 varchar 35 10 CITY varchar 20 10 PROV varchar 10 10 COUNTRY varchar 15 10 PHONE varchar 20 10 PHONE2 varchar 20 1SALESREP3 SALESREP_ID numeric 9 00 BU_ID numeric 9 10 SALESREP varchar 6 10 REPNAME varchar 50 1
Hope you get it! :) here is my query...select distinct c.custno,c.company, substring(c.postalcode,1,3) Postal, (select distinct count(c.postalcode) from customer c, salesrep sr, sales s where c.salesrep_id = 1215 and s.salesrep_id = c.salesrep_id and s.year = 2000) Postal_Cnt,--group by c.postalcode, s.salesrep_id),s.sales_id, sr.salesrep, s.salesrep_id, s.year, sr.repnamefrom salesrep sr, customer c, sales swhere sr.salesrep = 'WGA'and s.year = 2000and sr.salesrep_id = c.salesrep_idand c.salesrep_id = s.salesrep_idand sr.bu_id = c.bu_idand c.bu_id = s.bu_idand c.customer_id = s.customer_id
Hope you can help! :) "