SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Identifying Customers Served Over Year
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

djb27
Starting Member

USA
1 Posts

Posted - 02/26/2013 :  22:02:22  Show Profile  Reply with Quote
Hi Everyone,

I have 3 tables: BASKET, STORE_MSA, and SKUINFO having between hundreds and thousands of rows of data. I am trying to identify the number of customers (in the table defined as BASKETNO) served across stores over the year. I only need to identify the customers from Illinois.

BASKET has the following columns: BASKETNO, STORE, DEPT, DEPTDESC, STYLE, SKU, QTY, AMT, RETAIL, ORGPRICE, COST, BRAND, SALEDATE

STORE_MSA has the following columns: STORE, CITY, STATE, ZIP, MSA, MSA_NAME, MSA_POP, MSA_REGION

Some assistance would be greatly appreciated!

David Burr

khtan
In (Som, Ni, Yak)

Singapore
17587 Posts

Posted - 02/26/2013 :  22:11:11  Show Profile  Reply with Quote
probably something like this

SELECT     COUNT (*)
FROM       BASKET b
INNER JOIN STORE_MSA s ON b.STORE = s.STORE
WHERE      b.SALEDATE BETWEEN '2012-01-01' AND '2012-12-31'

AND CITY = 'xxx'
if it is not what you wanted, please do post some sample data and the expected result


KH
Time is always against us


Edited by - khtan on 02/26/2013 22:12:45
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 02/26/2013 :  23:08:15  Show Profile  Reply with Quote
if SALEDATE is of type datetime use this to cover complete date range

SELECT     COUNT (*)
FROM       BASKET b
INNER JOIN STORE_MSA s ON b.STORE = s.STORE
WHERE      b.SALEDATE >='2012-01-01' AND b.SALEDATE<'2013-01-01'

AND STATE = 'IL'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 02/26/2013 :  23:16:08  Show Profile  Reply with Quote
also see
http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000