I have create a table with 3 columns @UserDefinedSectionData with XML datatype, @UserDefinedModuleId with INT datatype and @UserDefinedTabId with INT datatype.
I need to insert the whole XML file into database, in T-SQL i need to read path from my local PC, example: C:\\Websites\\dnndev.me\\XML\\abc.xml, after read it and insert the whole xml into UserDefinedSectionData column which is XML datatype.
How can I do it?
I use this syntax:
DECLARE @xml_data XML,
@path_file nvarchar(260),
@cmd nvarchar(max);
SET @path_file = N'C:\Folder\File.XML';
/* get XML file */
SET @cmd = 'SELECT @xmlText = BulkColumn FROM OPENROWSET(BULK '
+ '''' + @path_file + ''''
+ ', SINGLE_BLOB) x;';
EXEC sp_executesql @cmd, N'@xmlText XML OUTPUT', @xmlText = @xml_data OUTPUT;
You must grant permission to the account that runs SQL Server agent.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.