File Write

bisonn Oct 20th, 2019 (edited) 151 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. declare @File varchar(255) = 'C:\Nvaision\ra215\Test\answ_'+replace(replace(right(convert(varchar(16),getdate(),120),11),' ','_'),':','')+'.xml'
  2. declare @OLE int, @FileID int
  3. declare @xmlF xml
  5. set @xmlF = (select [name] Name, getdate() t from sys.databases a for xml raw, root('Bases'))
  7. exec sp_OACreate 'Scripting.FileSystemObject', @OLE OUT
  8. exec sp_OAMethod @OLE, 'OpenTextFile', @FileID OUT, @File, 2, 1
  9. exec sp_OAMethod @FileID, 'WriteLine', Null, '<?xml version="1.0" encoding="windows-1251" standalone="yes"?>
  10. '
  11. exec sp_OAMethod @FileID, 'WriteLine', Null, @xmlF
  12. exec sp_OADestroy @FileID
  13. exec sp_OADestroy @OLE
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand