For review

0

Please login or register to vote for this query.

(click on this box to dismiss)

Poker Meta

Q&A about the site for serious players and enthusiasts of poker

IF OBJECT_ID('tempdb..#Customer') IS NOT NULL
    DROP TABLE #Customer
CREATE TABLE #Customer(
    UserID INT IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
    FirstName VARCHAR(150), 
    LastName VARCHAR(150),
    UserCreatedDate DATETIME	
)

IF OBJECT_ID('tempdb..#CustomerStatusHistory') IS NOT NULL
    DROP TABLE #CustomerStatusHistory
CREATE TABLE #CustomerStatusHistory(
    StatusID INT IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
    UserID INT, 
    Status VARCHAR(25),
    StatusCreatedDate DATETIME	
)

INSERT INTO #Customer 
VALUES ('Jack','Sprat',GETDATE());
INSERT INTO #Customer 
VALUES ('Jane','Sprat',GETDATE());
INSERT INTO #Customer 
VALUES ('Jake','Sprat',GETDATE());
INSERT INTO #Customer 
VALUES ('Jill','Sprat',GETDATE());


INSERT INTO #CustomerStatusHistory 
VALUES (1,'Pending',GETDATE());
INSERT INTO #CustomerStatusHistory 
VALUES (1,'Active',GETDATE());

INSERT INTO #CustomerStatusHistory 
VALUES (2,'Pending',GETDATE());
INSERT INTO #CustomerStatusHistory 
VALUES (2,'Active',GETDATE());
INSERT INTO #CustomerStatusHistory 
VALUES (2,'Canceled',GETDATE());

INSERT INTO #CustomerStatusHistory 
VALUES (3,'Pending',GETDATE());
INSERT INTO #CustomerStatusHistory 
VALUES (3,'Active',GETDATE());

INSERT INTO #CustomerStatusHistory 
VALUES (4,'Pending',GETDATE());


SELECT MAX(StatusID) FROM #CustomerStatusHistory
WHERE Status = 'Active'
GROUP BY StatusID

DROP TABLE #Customer
DROP TABLE #CustomerStatusHistory

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results