How to delete files on the directory via MS SQL Server -


i trying delete file directory inside windows using following query,

exec xp_cmdshell 'del "c:\root\sfd_devtracker\'+@deletefile + '"'; 

when execute command gives following error,

incorrect syntax near '+'. 

in @deletefile variable have filename have delete. have done wrong here?

xp_cmdshell requires literal string passed parameter. cannot construct value on fly.

try this:

declare @cmd nvarchar(max) =  'xp_cmdshell ''del "c:\root\sfd_devtracker\' + @deletefile + '"'''; exec (@cmd) 

Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -