It is not completely clear to me what the logic is. So copy this code, and run it - it won't insert anything into the table - it will just show you what it would insert. If that looks right, then you can uncomment the line that starts with --insert into.Also, if there is no corresponding row in TCTable, this will not insert a row into SalesQuotation. Similarly, if there are multiple rows in the TCTable that matches the TCId, then it will insert as many rows into the SalesQuotation table.declare @TCdetailsXML xml = '<TCDetailsList> <TCDetails> <quotationId>164</quotationId> <TCId>Term1</TCId> <TC>g1</TC> </TCDetails> <TCDetails> <quotationId>164</quotationId> <TCId>Term2</TCId> <TC>g2</TC> </TCDetails></TCDetailsList>';with cte as( select TCdetails.Details.value('quotationId[1]','numeric(9)') as quotationId, TCdetails.Details.value('TCId[1]','varchar(255)') as TCid, TCdetails.Details.value('TC[1]','varchar(500)')as TC from @TCdetailsXML.nodes('//TCDetailsList/TCDetails') as TCdetails(Details))--insert into SalesQuotation(quotationId,TCid,TC)select c.quotationId, a.TCId, c.TCfrom cte c inner join TCTable t on c.TCId = a.TCName