I've written a SQL process that export (3) files. As you may or may not know, when leveraging the SQLCMD Utility, you have the ability to export with or without headers. However, if you export with headers, the 2nd line is just dashes and pipes - which cannot obviously be loaded into a target system.
To get around that, I've been exporting without a header, and then concatenating (2) files together - 1 with the header and 1 with the contact.
I'm doing it like such:
Code: Select all
PUSHD "%LOCALEXPORTPATH%"
SET "F="
FOR %%F IN ( Program Project Task ) DO (
IF EXIST "%%F.txt" DEL /F /Q "%%F.txt">nul
ECHO Started ^: %%F View SQL Export >>%LOGFILE%
CALL "%SQL_CMD_PATH%" -S %MSSQL_SRVR% -U %MSSQL_USER% -P %MSSQL_PSSWRD% -W -s"|" -i "%SQLPATH%TEMPO_%%F.sql" -o "%%FZ.txt"
IF %ERRORLEVEL%==0 (
ECHO Completed ^: %%F View SQL Export >>%LOGFILE%
) ELSE (
ECHO Failed ^: %%F View SQL Export >>%LOGFILE%
SET "F=T"
GOTO PreAbnormalExit
)
ECHO %%F | FINDSTR "Program">nul && (
ECHO Parent_Node^|Name^|Alias^|ProjectType>>"%%F.txt"
COPY /Y "%%F.txt" + "%%FZ.txt">nul
DEL /F /Q "%%FZ.txt">nul
)
ECHO %%F | FINDSTR "Project">nul && (
ECHO Parent_Node^|Name^|Alias^|PF_TherapeuticArea^|PrePostCS^|ProjectType>>"%%F.txt"
COPY /Y "%%F.txt" + "%%FZ.txt">nul
DEL /F /Q "%%FZ.txt">nul
)
ECHO %%F | FINDSTR "Task">nul && (
ECHO Parent_Node^|Name^|Alias>>"%%F.txt"
COPY /Y "%%F.txt" + "%%FZ.txt">nul
DEL /F /Q "%%FZ.txt">nul
)
)
POPD
Here is the file:
Code: Select all
Parent_Node|Name|Alias|ProjectType
-----------|----|-----|-----------
PF_RESEARCH_TOTAL|PF_CMC_Research|CMC Research|Compound
PF_RD_TOTAL|PF_GA|R&D platforms, initiatives & infrastructure|Non-Compound
Is there a way to just delete the 2nd line of all (3) files?
Thanks!