How tio Select unpaid payments SQL.
I have two tables, one is customer and other is payment.
DECLARE @Customer TABLE (CsID INT, CsName VARCHAR(20), Credit Decimal(18,2), IssuedOn Datetime)
INSERT INTO @Customer (CsID, CsName, Credit, IssuedOn) VALUES (1, 'Akhil', '20000', '19-Oct-2019')
INSERT INTO @Customer (CsID, CsName, Credit, IssuedOn) VALUES (2, 'Prajeesh', '15000', '15-Dec-2019')
INSERT INTO @Customer (CsID, CsName, Credit, IssuedOn) VALUES (3, 'Shruthi', '12000', '17-Dec-2019')
INSERT INTO @Customer (CsID, CsName, Credit, IssuedOn) VALUES (4, 'Joseph', '18000', '20-Jan-2020')
DECLARE @payment TABLE (CsNo INT, PaidAmount Decimal(18,2), Balance Decimal(18,2), PaidDate Datetime)
INSERT INTO @payment (CsNo, PaidAmount, Balance, PaidDate) VALUES (1 , '2000', '18000', '1-Nov-2019')
INSERT INTO @payment (CsNo, PaidAmount, Balance, PaidDate) VALUES (1 , '1000', '17000', '5-Dec-2019')
INSERT INTO @payment (CsNo, PaidAmount, Balance, PaidDate) VALUES (2 , '5000', '10000', '8-Jan-2020')
INSERT INTO @payment (CsNo, PaidAmount, Balance, PaidDate) VALUES (3 , '2000', '10000', '3-Jan-2020')
INSERT INTO @payment (CsNo, PaidAmount, Balance, PaidDate) VALUES (4 , '2000', '16000', '10-Feb-2020')
INSERT INTO @payment (CsNo, PaidAmount, Balance, PaidDate) VALUES (3 , '3000', '7000', '6-Feb-2020')
DECLARE @expectResult TABLE (CsNo INT, CsName VARCHAR(20), Balance Decimal(18,2))
INSERT INTO @expectResult (CsNo, CsName, Balance) VALUES (1 , 'Akhil', '17000') -- he did'nt pay after December 2019
INSERT INTO @expectResult (CsNo, CsName, Balance) VALUES (2 , 'Pajeesh', '10000') -- he did'nt pay after Jan 2020
-- All others are paid up to February 2020
expectResult table contains the result table which I wanted to select.