I want to add a timestamp to the outputfile from within a .sql
file. Fullpath variable appears to be created correctly but :out
throws an error. Run anywhere code is below. Any idea why the error happens, and how to fix it?
-- control output of test results
Declare @filepath Varchar(200)
set @filepath='C:\Users\XXXXXX\Desktop\Automation Rewrite\Enrollment\Test Results\'
declare @filename varchar(100)
set @filename = 'enrollment_OH_MD_1_' + CONVERT(varchar(12),getdate()) + '.txt'
select @filename
declare @fullpath Varchar(200)
set @fullpath = '"'+ltrim(@filepath+@filename)+'"'
select @fullpath
:out @fullpath
error received: Unable to redirect output to @fullpath. Access to the path 'C:\WINDOWS\system32@fullpath' is denied.