ESTE ES EL CODIGO
Código:
SET @FileName = REPLACE(@ruta+'S1MESReject_'+CONVERT(char(8),GETDATE(),112)+ '_'+SUBSTRING(CONVERT(varchar(8),GETDATE(),108),1,2)+''+SUBSTRING(CONVERT(varchar(8),GETDATE(),108),4,2)+'.txt','/','-') SET @bcpCommand = 'bcp "SELECT Date, Material, Machine, Plant, Shift, Part, RejectPoint = convert(varchar(30),RejectPoint), RejectKgs, RejectThs FROM SCRAP.dbo.TB_Scrap " queryout "' SET @bcpCommand = @bcpCommand + @FileName + '" -c -t"|" -r \n -T -S '+@servidor+' -U '+@usuario+' -P '+@contraseña EXEC xp_cmdshell @bcpCommand