Generate .bat to execute SQL Server queries

1

I have the following series of questions:

delete from OPENQUERY (MYSQL, 'SELECT * from clientes2 WHERE IDCliente>2')

insert into OPENQUERY (MYSQL, 'SELECT IDCliente, Grupo, Codigo,
Denominacion, CUIT, TipoCliente, Responsable1, Activo FROM clientes2')
select IDCliente, Grupo, Codigo, Denominacion, CUIT, TipoCliente,
Responsable1, Activo from SQLSERVERDB.dbo.Clientes WHERE IDCliente > 3

Is there a way to generate a file so that someone who has no idea of SQL can execute these 2 queries sensibly without having to enter the management studio?

    
asked by Pepemujica 03.11.2016 в 18:18
source

1 answer

1

You can save your queries in a "query.sql" file and have it called from a batch with the sqlcmd command, for example:

@echo off
cd "C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC0\Tools\Binn\"
sqlcmd.exe -S DBserverName -U username -P p@ssword -i "C:\query.sql" -s "," | findstr /V /C:"-" /B >"c:\output.csv"

Run Transact-SQL script files using sqlcmd

The sqlcmd utility

    
answered by 03.11.2016 в 18:25