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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Customer Log into storefront but no Sales Order!

Author  Topic 

fawadafr
Starting Member

47 Posts

Posted - 2010-05-26 : 15:57:21
I have written the following SQL statement to generate a report of all customers who log into our storefront but don't place any order. I wanted to share my work to find out if you have better solution and recommendation.


SELECT c.CustomerID
,c.FirstName
,c.LastName
,c.CompanyName
,c.BillingAddress1
,c.BillingAddress2
,c.City
,c.State
,c.PostalCode
,c.Country
,c.EmailAddress
FROM Customers AS c
WHERE NOT EXISTS
(SELECT *
FROM Orders AS o
WHERE o.CustomerID = c.CustomerID AND
o.OrderDate BETWEEN '2010-04-01' AND '2010-04-30'
) AND
c.AccessKey = 'C' AND
c.LastLogin BETWEEN '2010-04-01' AND '2010-04-30'
ORDER BY c.CustomerID
GO


Thank you,

--
Fawad Rashidi
Web Developer
www.fawadafr.com

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-05-26 : 15:59:32
I would change the date format to 'yyyymmdd' to be safe. Apart form that it looks pretty straight forward.
Go to Top of Page
   

- Advertisement -