I am trying to execute some sqlcmd through T-SQL on SQL Server 2008. The part of my code where I check the data file size and if the data file size is not 0, then start the deletion so that I can use BCP in the new data.
Below is my code that is not executing:
SET @myVariable = ' SETLOCAL FOR %%R IN (X:\Main Folder\Data\' +@databaseName +'_' +@tableName +'.dat) DO SET size=%%~zR IF %size% NEQ 0 ( SQLCMD -E -S my-server-name -Q "DELETE FROM ' +@databaseName +'.' +@schemaName +'.' +@tableName +';" >> X:\Main Folder\Log\Log.txt )' EXEC master..xp_cmdshell @myVariable
For some reason, when I execute my stored procedure, the above code is skipped because it does not throw away any error messages.
EDIT: After reconfiguring the interval and my code, @myVariable is now executing. However, it still does not work with respect to the fact that it still deletes the table, even if the data file size = 0. However, when I hard-code it in a batch file, it works fine. Any ideas?
source share