A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @Spunny ,
I don't quite understand what your problem is. When the second transaction comes in, you will delete all the data in the @tmpTbl table, and all the records in the TRANS table will be saved, so you only need to return the withdraw transaction data from the TRANS table.
Of course, as you said, you are not sure which table the data is in, you can find it according to the following code:
DECLARE @tmpTbl table
(
ID int,
CommonID int,
Type varchar(100),
AccountType varchar(100),
Amount decimal(10,2),
ClientID int,
AccountID int
)
Insert into @tmpTbl
SELECT 1, 1234, 'Deposit', 'Checking Account', 100.00, 2, 50
select * from @tmpTbl
Insert into Trans Select * from @tmpTbl
select * from Trans
select * from @tmpTbl where Type='Withdraw'
union all
select * from TRANS where Type='Withdraw'
DELETE FROM @tmpTbl
Insert into @tmpTbl
SELECT 2, 1234, 'Withdraw', 'Checking Account', 100.00, 2, 50
select * from @tmpTbl
select * from @tmpTbl where Type='Withdraw'
union all
select * from TRANS where Type='Withdraw'
The union all statement in the above code can return all Withdraw data in the two tables:
select * from @tmpTbl where Type='Withdraw'
union all
select * from TRANS where Type='Withdraw'
If you have any question, please feel free to let me know.
If the response is helpful, please click "Accept Answer" and upvote it.
Best Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.