I'm need your help to insert vales into my table based on criteria.
My table & its values are as follows.
CREATE TABLE [TEST].[dbo].[bank] (
[DATE] datetime,
[CHQNO] float,
[Deposit] float,
[Withdrawal] float,
[Status] nvarchar(255)
)
INSERT INTO [Test].[dbo].[bank]
([DATE]
,[CHQNO]
,[Deposit]
,[Withdrawal])
VALUES
('2016-04-19',533247,1975000,NULL)
,('2016-04-19',533247,NULL,1975000)
,('2016-05-05',NULL,1947293.42,NULL)
,('2016-05-05',NULL,1947293.42,NULL)
,('2016-06-03',535199,1930000,NULL)
,('2016-06-04',535199,NULL,1930000)
,('2016-08-04',NULL,195000,NULL)
,('2016-08-05',628490,5000,NULL)
,('2016-08-05',628490,NULL,5000)
,('2016-12-30',750200,15000,NULL)
,('2016-12-31',326500,NULL,15000)
I want to update the value in [Status] column as 'RTN' if there is two records with same value in [CHQNO] column & same value in [Deposit] & [Withdrawal] columns.
I'm expecting a table like this.
DATE CHQNO Deposit Withdrawal Status
19-Apr-16 533247 1975000 NULL RTN
19-Apr-16 533247 NULL 1975000 RTN
5-May-16 NULL 1947293.42 NULL NULL
5-May-16 NULL 1947293.42 NULL NULL
3-Jun-16 535199 1930000 NULL RTN
4-Jun-16 535199 NULL 1930000 RTN
4-Aug-16 NULL 195000 NULL NULL
5-Aug-16 628490 5000 NULL RTN
5-Aug-16 628490 NULL 5000 RTN
30-Dec-16 750200 15000 NULL NULL
31-Dec-16 326500 NULL 15000 NULL
Can someone help me on how to code to check & insert the values into [Status] column.
Thank you very much.