Write variable content in file at specific point

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kerstinvo
Posts: 2
Joined: 11 May 2018 05:58

Write variable content in file at specific point

#1 Post by kerstinvo » 11 May 2018 06:25

Hello team,

I have a batch wiht 1 parameter from user and store the parameter %1 as variable.

then I will write that value in a file, that contains an SQL insert command. The problem is to give that variable value for further processing.
Parameter:

Code: Select all

::parameter usage
::Changenr. angegeben, dann fortfahren, sonst Usage anzeigen und exit
if [%1]==[] goto usage
::Variable für Param 1
set chnr=%1
echo "changnr: %chnr%"

::exit ohne DOS-Fenster schließen
:usage
@echo Usage: Changenr von cm_prod fünfstellig angeben! Bsp: mergeAPM-file.bat 12345
exit /B 1

File zd_zd.txt contains the sql statement: part APMoA Changenr. %chnr%' should be the contain the given changenumber value

--gültig bis Vortag nächste APMoA

Code: Select all

insert into ZD_ZD(ZDS,ZDAUSFUEHRUNGSDATUM,ZDREGELUPDATE,ZDDATV,ZDDATB,ZDPRODUKT,ZDPRODUKTRELEASE,ZDPRODUKTRELEASEVERSION) 
values(to_char(sysdate,'YYYYMMDDHH24SS'),sysdate,'APMoA vom '||to_char(sysdate,'DD')||'.'|| to_char(sysdate,'MM')||'.'||to_char(sysdate,'YYYY')||' '||to_char(sysdate,'HH24')||':'||to_char(sysdate,'SS'),to_char(sysdate,'YYYYMMDD'),to_char(sysdate+6,'YYYYMMDD'),'Zentraldateien 1.0',to_char(sysdate,'YYYY'),'APMoA Changenr. %chnr%');
also insert the content with sql insert into the Batch skript and referenced the variable with echo "sql statement> >> ZD_ZD-insert.text did not work.

Does anyone have a hint ?

Thanks
Kerstin
Last edited by Squashman on 11 May 2018 11:02, edited 1 time in total.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Write variable content in file at specific point

#2 Post by aGerman » 12 May 2018 14:03

Writing at a certain position isn't possible. You can either append new content at the end or you can write the whole file new.
Does your SQL script only consist of the two lines that you posted? In that case you might be able to write it using the parameter variable without a temporary file like that:

mergeAPM-file.bat

Code: Select all

@echo off &setlocal
if "%~1"=="" (
  echo Usage: Changenr von cm_prod fuenfstellig angeben! Bsp: CALL "mergeAPM-file.bat" 12345
  pause
  exit /b 1
)

>"zd_zd.txt" (
  echo insert into ZD_ZD(ZDS,ZDAUSFUEHRUNGSDATUM,ZDREGELUPDATE,ZDDATV,ZDDATB,ZDPRODUKT,ZDPRODUKTRELEASE,ZDPRODUKTRELEASEVERSION^) 
  echo values(to_char(sysdate,'YYYYMMDDHH24SS'^),sysdate,'APMoA vom '^|^|to_char(sysdate,'DD'^)^|^|'.'^|^| to_char(sysdate,'MM'^)^|^|'.'^|^|to_char(sysdate,'YYYY'^)^|^|' '^|^|to_char(sysdate,'HH24'^)^|^|':'^|^|to_char(sysdate,'SS'^),to_char(sysdate,'YYYYMMDD'^),to_char(sysdate+6,'YYYYMMDD'^),'Zentraldateien 1.0',to_char(sysdate,'YYYY'^),'APMoA Changenr. %~1'^);
)
Steffen

kerstinvo
Posts: 2
Joined: 11 May 2018 05:58

Re: Write variable content in file at specific point

#3 Post by kerstinvo » 14 May 2018 02:44

Hello Steffen,

thanks for the hint. It is working. :D

Post Reply