I am trying to create a file using the SP - MSSQL. before creating a file i want to check Whether the file exist . IF Exist i want to replace a new one or else create a new file. Want to return a value while executing the cmdshell in sql.
DECLARE @Text AS VARCHAR(100)
DECLARE @Cmd AS VARCHAR(100)
DECLARE @exstFile AS VARCHAR(100)
set @cmd = 'IF EXIST Z:\AppTextFile.txt (ECHO 1) ELSE (ECHO 0)'
EXEC @cmd = xp_cmdshell @cmd
select @cmd datum