Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Identifying Customers Served Over Year

Author  Topic 

djb27
Starting Member

1 Post

Posted - 2013-02-26 : 22:02:22
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)

17689 Posts

Posted - 2013-02-26 : 22:11:11
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
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-26 : 23:08:15
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

52326 Posts

Posted - 2013-02-26 : 23:16:08
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
   

- Advertisement -