Forbidden?!? What kind of place forbids you to use such a tool. Please make us a 5 course meal with lobster and steak, but use of the kitchen is forbidden!. use wooden utensils.
try this. For now just use a simple test SQLTEST.SQL file
The following is broken into multi files in order to fit this forum's textarea box.
You will have to make it into 1 long line.
FOR /F "tokens=1 delims=," %%G IN (instances_list.txt)
DO FOR /F "tokens=1 delims=," %%G IN (instances_list.txt)
DO SQLCMD -S %%G -i "SQLTEST.sql" -m 12 -E
your test sql file should include the following. Make sure you use a database where this command will happen. unless this is also forbidden
if exists(select 1 from sys.tables where name = 'SQLCMD')
begin
drop table dbo.SQLCMD
end
if not exists(select 1 from sys.tables where name = 'SQLCMD')
begin
create table dbo.SQLCMD(areyouthere varchar(50))
end
FOR /F "tokens=1 delims=," %%G IN (instances.csv) DO FOR /F "tokens=1 delims=," %%G IN (instances.csv) DO SQLCMD -S %%G -i "ACL.sql" -m 12 -E -o "output_protocol.txt"
How do I change output_protocol.txt so that it is not overwritten but is written as an append?
FOR /F "tokens=1 delims=," %%G IN (dblist.csv) DO FOR /F "tokens=1 delims=," %%G IN (dblist.csv) DO SQLCMD -S %%G -i "acl.sql" -m 12 -E -o "protocol_output.txt"
How do I make a change, but the protocol (-o "protocol_output.txt") has grown (=> appending)?
FOR /F "tokens=1 delims=," %%G IN (instanceslist.csv) DO FOR /F "tokens=1 delims=," %%G IN (instanceslist.csv) DO SQLCMD -S %%G -i "acl.sql" -m 12 -E -o "protocol_output.txt"
If I have 10 different SQL instances in INSTANCES_LIST.csv, then I have 10x10 records in PROTOCOL_OUTPUT.txt, for each SQL instance from INSTANCES_LIST.csv the code is executed 10 times.
How do I make the SQL code from ACL.sql run just once and get a 10x1 record in PROTOCOL_OUTPUT.txt?