I have scenario to use the Temporary user defined type variable in transaction, but the temporary variable is not clearing the value inside the transaction.
CREATE TYPE [int_list_table] AS TABLE([item_id] [int] NULL)
GO
DECLARE @int_val BIGINT
-- Create a Temp table with 5 rows
;WITH TEMP(int_val)
AS
(SELECT 1
UNION ALL
SELECT int_val = 1 + int_val FROM TEMP WHERE int_val < 5
)SELECT * INTO #int FROM TEMP;
SET NOCOUNT ON
DECLARE IntCursor CURSOR FAST_FORWARD FOR
SELECT int_val FROM #int
OPEN IntCursor
FETCH NEXT FROM IntCursor INTO @int_val
WHILE(@@FETCH_STATUS = 0)
BEGIN
BEGIN TRY
BEGIN TRANSACTION
-- a temprory table to store the integer value
DECLARE @table [int_list_table]
INSERT INTO @table
SELECT 1 WHERE 2 = @int_val
-- Actually @table should have resultset only at @int_val = 2, But once it filled with values even for 3 and 4
SELECT
'User Table Type Value' = item_id,
'Loop Integer Value' = @int_val
FROM
@table
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK
END CATCH
FETCH NEXT FROM IntCursor INTO @int_val
END
CLOSE IntCursor
DEALLOCATE IntCursor
SET NOCOUNT OFF
For the above query the output is

Actually it has to return only the record for 2, but it is not clearing the value once it is initialized. Please guide me to proceed further.
The declaration of the data type does not clear the content of the table. Once the table variable is there it will have whatever you have put into it. The execution of the code does not even have to pass the place where the variable is declared. This will work as well.
You only have to make sure that the declaration is before any references to the variable.
To fix your code so it does what you want you can of course add
delete from @tablejust before the insert statement.