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 -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -