I have a batch which takes the name of the file and path of a parameter in a table and then executes a select and saves it in a txt. The problem that is occurring is that in the last line I create a record with NULL (I am going to attach an image) which makes the error that the system takes this file. Then I copy the batch REM - PROOF
for /f %%A in ('sqlcmd -S Vane -d PEPE-U sa -P Vane -Q "set nocount on;select (SELECT Valor FROM ParametrosVarios WHERE Codigo = 1000)+NombreArchivo+replace(convert(varchar,(SELECT FechaProcesoAnterior FROM para),2),'.','')+'.txt' FROM Interfaz_NombresArchivos WHERE Id=3"') do set Nombre="%%A"
SET result=%Nombre:/= %
echo %result%
sqlcmd -S Vane -d PEPE-U sa -P Vane -Q "set nocount on; delete from Interfaz_Prueba where fechaejecucion = convert(varchar(10),getdate(),120)"
sqlcmd -S Vane -d PEPE -U sa -P Vane -Q "set nocount on; BEGIN exec sp_Interfaz_Prueba END"
sqlcmd -S Vane -d PEPE -U sa -P Vane -Q "set nocount on; select CAST(entidad as varchar)+NroOperacion+cast(SucursalOperacion as varchar)+CAST(entidad as varchar)+cast(Producto as varchar)+cast(Subproducto as varchar)+Moneda+cast(SucursalOperacion as varchar)+replicate(' ',4)+cast(CanalDeVenta as varchar)+cast(OficialVenta as varchar)+cast(OficialComercial as varchar)+replicate(' ',4-datalength(OficialComercial))+cast(saldo as varchar)+cast(saldo as varchar)+fechaInicio+'9999-12-31'+EstadoDelContrato+FechaEstado+replicate(' ',2)+replicate(' ',2)+replicate(' ',8)+replicate(' ',20)+'0000BANKTRADE'+REPLICATE(' ',111)+TipoMovimiento from Interfaz_Prueba where fechaejecucion = convert(varchar(10),getdate(),120)" -o %result% -W -w 1024 -s"" -h-1