I'm doing some testing in SSMS with various XML files on my LOCAL disk (in my C:\Temp folder), but I am connected to a remote test SQL Server. Is there any way to do something like this:
DECLARE @xml xml
-- Want to read from my local, but this attempts to read from the SQL Server's C drive
SELECT @xml = CONVERT(XML, BulkColumn)
FROM OPENROWSET(BULK 'C:\Temp\Test.xml', SINGLE_BLOB) AS x;
-- Insert into table on the remote SQL Server
INSERT INTO dbo.MyTable (StatementType, OperatingDate, StatementAmount)
SELECT doc.col.value('(StatementType)[1]', 'nvarchar(100)') StatementType
,doc.col.value('(OperatingDate)[1]', 'nvarchar(100)') OperatingDate
,doc.col.value('(StatementAmount)[1]', 'numeric(12,2)') StatementAmount
FROM @xml.nodes('/Level1/Level2') doc(col)
I've searched for the answer to this, but have not found it. And yes, I know I could create a test SQL Server locally on my machine, and no, I don't have access to copy the test XML files onto the SQL Server machine. But really, I just want to know if there's any way to do what I am asking.
Only if u are in a protected network try this. Share a folder on your computer and put there your file. Grant access to this folder to everyone.
In the query aim to your pc \yourpc\folderwithonlyonefile\file.xml
Lmk!!