Вы можете попробовать код ниже -
drop table if exists #table1 -- Using Temp tables for example
Create table #table1 (SNO INT, EvID varchar(20), Report xml)
drop table if exists #table2
Create table #table2 (Name nvarchar(50), Emp_Address nvarchar(100), City nvarchar(50),
Salary numeric(18,8), PF numeric(18,8)) -- Column taken as provided as sample XML data. Choose the data type according to your need.
BULK INSERT #table1 FROM 'C:\<FolderLocation>\<YourFileName>.<FileExtension>'
WITH (
CODEPAGE = 'RAW', FIRSTROW = 2, FIELDTERMINATOR = ','
)
select * from #table1
INSERT #table2
SELECT Report.value('(/employee/name)[1]', 'varchar(40)') AS Name,
Report.value('(/employee/location/Emp_Address)[1]', 'varchar(100)') AS Emp_Address,
Report.value('(/employee/location/city)[1]', 'varchar(50)') AS City,
Report.value('(/employee/Compensation/Salary)[1]', 'numeric(18,8)') AS Salary,
Report.value('(/employee/Compensation/PF)[1]', 'numeric(18,8)') AS PF
FROM #table1 -- Use your XML DOM structure to get the proper values
select * from #table2
Обратите внимание, я использовал тип данных XML для хранения значения столбца отчета. Value()
будет работать, только если тип данных столбца будет XML.