sparks
2012-08-06 12:00:34 UTC
customerID PurchaseDate PurchaseID
000000011 2008-09-30 00:00:00 50
000000011 2008-10-30 00:00:00 175
000000011 2008-03-20 00:00:00 42
000000022 2008-03-20 00:00:00 209
000000022 2008-03-20 00:00:00 223
000000022 2008-03-20 00:00:00 312
000000022 2008-03-20 00:00:00 391
000000022 2008-03-20 00:00:00 430
000000022 2008-03-20 00:00:00 553
000000044 2008-09-30 00:00:00 50
000000044 2008-10-30 00:00:00 50
000000044 2008-11-30 00:00:00 50
000000044 2008-11-30 00:00:00 50
000000044 2008-11-30 00:00:00 50
000000044 2008-11-30 00:00:00 50
I need to make a new table from this data.
Its the only place where they have stored the customerID and date but
I only need the first occurance of each date.
so the output would be something like this.
customerID PurchaseDate
000000011 2008-09-30 00:00:00
000000011 2008-10-30 00:00:00
000000011 2008-03-20 00:00:00
000000022 2008-03-20 00:00:00
000000044 2008-09-30 00:00:00
000000044 2008-10-30 00:00:00
000000044 2008-11-30 00:00:00
I did find a routine online but I am unsure what to do with it.
WITH CTE
AS (SELECT customerID,
PurchaseDate,
PurchaseID,
ROW_NUMBER() OVER (PARTITION BY PurchaseDate ORDER BY customerID asc ) AS Row
FROM dbo.tblCustomerPurchases)
SELECT customerID ,
PurchaseDate,
PurchaseID
FROM CTE
WHERE Row = 1 ;
yes this seems to output the correct data but I am unsure how to write this to a new table.
000000011 2008-09-30 00:00:00 50
000000011 2008-10-30 00:00:00 175
000000011 2008-03-20 00:00:00 42
000000022 2008-03-20 00:00:00 209
000000022 2008-03-20 00:00:00 223
000000022 2008-03-20 00:00:00 312
000000022 2008-03-20 00:00:00 391
000000022 2008-03-20 00:00:00 430
000000022 2008-03-20 00:00:00 553
000000044 2008-09-30 00:00:00 50
000000044 2008-10-30 00:00:00 50
000000044 2008-11-30 00:00:00 50
000000044 2008-11-30 00:00:00 50
000000044 2008-11-30 00:00:00 50
000000044 2008-11-30 00:00:00 50
I need to make a new table from this data.
Its the only place where they have stored the customerID and date but
I only need the first occurance of each date.
so the output would be something like this.
customerID PurchaseDate
000000011 2008-09-30 00:00:00
000000011 2008-10-30 00:00:00
000000011 2008-03-20 00:00:00
000000022 2008-03-20 00:00:00
000000044 2008-09-30 00:00:00
000000044 2008-10-30 00:00:00
000000044 2008-11-30 00:00:00
I did find a routine online but I am unsure what to do with it.
WITH CTE
AS (SELECT customerID,
PurchaseDate,
PurchaseID,
ROW_NUMBER() OVER (PARTITION BY PurchaseDate ORDER BY customerID asc ) AS Row
FROM dbo.tblCustomerPurchases)
SELECT customerID ,
PurchaseDate,
PurchaseID
FROM CTE
WHERE Row = 1 ;
yes this seems to output the correct data but I am unsure how to write this to a new table.