Why don't pass the entire path along with drive name as parameter. I mean D:\folder1\file.xml
.
Assuming that @FileName
parameter has the full path like D:\folder1\file.xml
then you can use dynamic query to achieve what you are looking for like below. Give it a try
DECLARE @sqlCommand varchar(1000)
SET @sqlCommand = 'set @XML = (SELECT '+ @XML + ' = CONVERT(XML, BulkColumn)
FROM OPENROWSET(BULK ' + @FileName +' , SINGLE_BLOB) AS x)';
declare @xml xml;
EXEC sp_executesql @sqlCommand, N'@XYZ xml output', @xml output
EXEC sp_xml_preparedocument @hDoc OUTPUT, @XYZ;
//rest of the code here