pass external parameters to sqlcmd via batch

1

I used it in oracle so I would like to know if you have any similar method for sqlserver (sqlcmd) .

Batch
sqlplus.exe system/123@localhost/xe @..\CRIA_TABELAS.sql "%last_bill%"

.sql file
SELECT * FROM TB_VENDAS_&1

What oracle interprets
SELECT * FROM TB_VENDAS_20180901

    
asked by anonymous 06.09.2018 / 14:18

1 answer

0

Rafael, in the SQL Server in the FROM clause it is not possible to use variables for the table name (or display); only literal. See the FROM clause documentation.

However, what you are requesting may be possible using script variable , because the -v option of the sqlcmd the use of something similar to parameter.

Also evaluate the use of the -q and -Q options.

-- código #1 - SCRIPT arquivo.sql
SELECT * FROM $(NomeTabela)

and

-- código #2 - BATCH
sqlcmd -v NomeTabela= "TB_VENDAS_20180901" -i arquivo.sql

In code # 2 you need to add the authentication part. I did not test the combination above. May contain error (s).

    
08.09.2018 / 18:34