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 |
Oliviaf2012
Starting Member
16 Posts |
Posted - 2012-08-01 : 17:41:53
|
I am trying to write an exists query to show me new customers.I want to return the number of customers who bought this month but never bought before - anyone know how to do that ? There is other criteria the customers need to meet ( the brand they purchased, their country etc) |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-01 : 19:08:53
|
[code]SELECT *FROM Table tWHERE BuyDate > = DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)AND BuyDate < DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0)AND NOT EXISTS (SELECT 1 FROM table WHERE CustomerID = t.CustomerID AND BuyDate < DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) AND other conditions...)AND other conditions....[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
Oliviaf2012
Starting Member
16 Posts |
Posted - 2012-08-02 : 07:04:49
|
Fantastic visakh16 that worked beautifully :) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-02 : 10:13:37
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|