Hi mahesh213,
You need to loop through the records and check if insurer fount then add the new attributes.
Refer below sample query.
SQL
DECLARE @Test AS TABLE (Id INT IDENTITY, Attribute VARCHAR(100), ReferenceNumber VARCHAR(50))
INSERT INTO @Test VALUES('insurer','abc')
INSERT INTO @Test VALUES('policyholder','efd')
DECLARE @RecordCount INT
SET @RecordCount = (SELECT COUNT(*) FROM @Test)
CREATE TABLE #Test(Id INT IDENTITY, Attribute VARCHAR(100), ReferenceNumber VARCHAR(50))
-- Insert existing records into Temp table.
INSERT INTO #Test
SELECT Attribute, ReferenceNumber
FROM @Test
DECLARE @Counter INT = 1
WHILE @Counter <= @RecordCount
BEGIN
DECLARE @Attribute VARCHAR(100), @ReferenceNumber VARCHAR(50)
SELECT @Attribute = Attribute, @ReferenceNumber = ReferenceNumber
FROM @Test WHERE Id = @Counter
-- Insert Attributes if Insurer found.
IF @Attribute = 'insurer'
BEGIN
INSERT INTO #Test VALUES ('Limit', @ReferenceNumber)
INSERT INTO #Test VALUES ('Period', @ReferenceNumber)
INSERT INTO #Test VALUES ('Duration', @ReferenceNumber)
END
SET @Counter = @Counter + 1
CONTINUE
END
SELECT * FROM #Test
DROP TABLE #Test
Screenshot