----------------------------------------------------------------
--                                                              
--  File:   Isolation1_S1.SQL                                   
--          Microsoft TPC-E Benchmark Kit Ver. 1.14.0-1031      
--          Copyright Microsoft, 2008-2015                  
--                                                              
--  Implements TPC-E Isolation test #1                          
--  P3 Test in Read-Write                                       
--                                                              
----------------------------------------------------------------
USE tpce
GO

BEGIN TRANSACTION

DECLARE @num_custs      bigint,
	    @cust_id	    bigint,
        @acct_id        bigint

--- get the number of customers in the database
SELECT  @num_custs      = COUNT(*) FROM CUSTOMER

--- select a random customer account for use in the test
SET     @cust_id        = CONVERT(bigint, RAND() * @num_custs) + 43000000001

SELECT  TOP 1
        @acct_id        = CA_ID
FROM    CUSTOMER_ACCOUNT
WHERE   CA_C_ID         <= @cust_id
ORDER   BY 1 DESC

--- run Trade Order Isolation 1
EXEC TradeOrder_Iso1_1  @acct_id

COMMIT
GO
