1

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm glad to help. Please consider to accept the answer if it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.