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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-07-06 : 07:45:29
|
| Paul writes "I'm bashing my head against a wall at the moment with a specific SQL Server problem. Can anyone help?Basically I have two tables - tblUsers and tblOrders. The relevant fields are:tblUsers.EmailtblUsers.DateJoinedtblUsers.ContactAllowedtblOrders.EmailtblOrders.DateUsers register but don't all place orders.I need to know two things. 1. How many users have agreed to be contacted and have not placed orders within a 6 week period.2. How many users have agreed to be contacted and not placed orders within a 6 week period but have had orders outside of that time period.I have tried the following but it comes up with the same figure which is unlikely.SELECT COUNT(DISTINCT tblUsers.Email) AS Expr1FROM tblUsers LEFT OUTER JOIN tblOrders ON tblUsers.Email = tblOrders.EmailWHERE (tblUsers.MFIContact = 1) AND (NOT (tblOrders.Date BETWEEN CONVERT(DATETIME, '2004-12-28 00:00:00', 102) AND CONVERT(DATETIME, '2005-02-08 00:00:00', 102))) AND (tblUsers.DateJoined <= CONVERT(DATETIME, '2005-02-08 00:00:00', 102)) SELECT COUNT(DISTINCT tblUsers.Email) AS Expr1FROM tblUsers LEFT OUTER JOIN tblOrders ON tblUsers.Email = tblOrders.EmailWHERE (tblUsers.MFIContact = 1) AND (NOT (tblOrders.Date BETWEEN '20041228' AND '20050208')) AND (tblOrders.Date < CONVERT(DATETIME, '2004-12-28 00:00:00', 102) OR tblOrders.Date > CONVERT(DATETIME, '2005-02-08 00:00:00', 102)) AND (tblUsers.DateJoined <= CONVERT(DATETIME, '2005-02-08 00:00:00', 102))Anyone any ideas?!?" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-06 : 09:18:56
|
quote: I have tried the following but it comes up with the same figure which is unlikely.
Then post some sample data and the result which is likelyMadhivananFailing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|
|