Long story short I have an SQL script that I run when an action falls over, I have a log with has all the information I need and I just replace certain parts of this SQL script with text from the log file.
My question: is there a way I can do this from a batch file?
Example
Log file contains query ID:123456 and EntityID:654321, 23123432, 345345435, 435435, 438980943, etc.
I have SQL script where I replace "QueryID" with the query id number from the log and also I want to replace "entityID" with all of the entityid's that are in the log file there are usually a few hundred.
Here's the SQL script
select *
from search_results
where search_id = ***query_id***
and entity_id in (select entity_id
from search_results
where search_id = ***query_id***
and entity_id in (***entityID***))
Above is the SQL script I run and I want to replace Query_id with the query id from the log file I have and then replace the Entity_ID with the entity ID's from the same log file
I've been trying to find a way round this for ages but I'm stuck I use the follow to extract the entity ID's to a file and then I just copy and paste them in to the SQL script
@ECHO OFF
for /f "tokens=4 delims=:" %%G in ('TYPE logfile.txt ^|FIND /i "EntityID"') do (
ECHO %%G,>>entity.txt
)
I can do the same for the query Id but as there is just the one id I just copy & paste it in.
In short I want to place a log in a directory/file and then run a Bat file to generate me the SQL script (in a text file).
Any help will be much appreciated :)
Extra information
I have to run this script to figure out what people in an eshot, the eshot has/hasn't been sent to so I can removed those people that have had the eshot sent to them and remove them from the list in SQL so the eshot can be set again and people don't get lots of emails.
The QueryID is the id of the list where the emails are listed and the entityID is the id of the email addresses in the list.
So in short the sql script finds the list of email address (via the QueryID) and then shows the email address the eshot has been sent to (via entityID's in the log file) so I can remove them from the list and resend the eshot and people don't get two emails.
This usually falls over when people have stupid characters in their email addresses.
Here's the log file I've removed data sensitive information.
> ==========================================================================================
>
> ------------------------------------------------------------------------------------------
> Domain :10007
> User :10725
> Language :1
> Entity :0
> Role :-1
> View :8997749 ()
> Region :8998836 ()
> Control :
> Date/Time :5 janvier 2015 15:49:33 UTC
> ==========================================================================================
> [15:49:33 UTC] TotalQueryIDs :1:
> [15:49:33 UTC] User :10725:
> [15:49:33 UTC] Template :20005406:
> !!! [15:49:33 UTC] queryID :96566:
> [15:49:33 UTC] QueryCount :781:
> [15:49:33 UTC] Count :1:
> !!! [15:49:33 UTC] EntityID :49891:
> [15:49:33 UTC] Contact :49891:
> [15:49:33 UTC] Today :05/01/15:
> [15:49:33 UTC] Time :16:49:
> [15:49:33 UTC] EmailID ::
> [15:49:33 UTC] posOfSign :7:
> [15:49:33 UTC] posOfSign :7:
> [15:49:33 UTC] posOfDot :10:
> [15:49:33 UTC] emailValidity ::
> [15:49:33 UTC] flag ::
> [15:49:33 UTC] Language :English:
> [15:49:33 UTC] Template1 :COBE8:
> [15:49:33 UTC] flag ::
> [15:49:33 UTC] --<*> RSH <*>--
> [15:49:33 UTC] TempName ::
> [15:49:33 UTC] DocCount :96:
> [15:49:33 UTC] BeforeAdd ::
> [15:49:33 UTC] AfterAdd ::
> [15:49:33 UTC] afterIF ::
> [15:49:33 UTC] preview :N:
> [15:49:33 UTC] preview :N:
> [15:49:34 UTC] DocCount :1:
> [15:49:34 UTC] countofATT ::
> [15:49:34 UTC] Today :05/01/15:
> [15:49:34 UTC] Time :16:49:
> [15:49:34 UTC] EMAILSEND ::
> [15:49:34 UTC] preview :N:
> [15:49:34 UTC] Role :111:
> [15:49:34 UTC] e1 ::>
> [15:49:34 UTC] e1 ::
> [15:49:34 UTC] DocCount :96:
> [15:49:34 UTC] DocCount :96:
> [15:49:34 UTC] e1 ::
> [15:49:34 UTC] countofATT ::
> [15:49:34 UTC] DocCount :1:
> [15:49:34 UTC] e1 ::
> [15:49:34 UTC] --<*> About to Save Journal <*>-->
> [15:49:34 UTC] --<*> Journal Saved <*>--
> [15:49:34 UTC] EmailID ::
> [15:49:34 UTC] Count :2:
> !!! [15:49:34 UTC] EntityID :49903:
> [15:49:34 UTC] Contact :49903:
> [15:49:34 UTC] Today :05/01/15:
> [15:49:34 UTC] Time :16:49:
> [15:49:34 UTC] EmailID ::
> [15:49:34 UTC] posOfSign :3:
> [15:49:34 UTC] Eshot :Y:
> [15:49:34 UTC] posOfSign :3:
> [15:49:34 UTC] posOfDot :11:
> [15:49:34 UTC] emailValidity ::
> [15:49:34 UTC] flag ::
> [15:49:34 UTC] Phone ::
> [15:49:34 UTC] Language :English:
> [15:49:34 UTC] Template1 :COBE8:
> [15:49:34 UTC] flag ::
Here is an example of what the SQL script should look like
select * from search_results where search_id =96566 and
entity_id in (select entity_id from search_results where search_id =96566
And entity_id in(49891,49903,51404,137395,137492,))
Thank you for all you help guys, really appreciate it.
Update
I've use the following (Thanks to @Keeghan McGarry) and get what I want but the entity id only shows the last one in the list, is there a way to get all the entity ID's to show up, FYI The log is called bo.txt and the script goes to sql.txt
@ECHO OFF
FOR /F "tokens=4 delims=:" %%e IN ('TYPE bo.txt ^|FIND /i "EntityID"') DO SET entity=%%e
FOR /F "tokens=4 delims=:" %%q IN ('TYPE bo.txt ^|FIND /i "queryID"') DO SET query=%%q
ECHO select * from search_results where search_id =%query% and entity_id in >> sql.txt
ECHO (select entity_id from search_results where search_id =%query%>> sql.txt
ECHO And entity_id in>> sql.txt
ECHO (%entity%))>> sql.txt
The above gives me this below but there should be these entity id's 49891,49903,51404,137395,137492,
select * from search_results where search_id =96566 and entity_id in (select entity_id from search_results where search_id =96566 And entity_id in (137492))
All help is really appreciated.