1

I am writing a shell script which will import the csv file to an already created table in SQL Server. I know how to retrieve the data to a file but doing reverse which I am not familiar with.

sqlcmd -S "$DB_HOST" -U "$DB_USER" -P "$DB_PASSWORD" -o "$mssqlresult" -s ","  -W -h -1 -Q "select query"

Any pointers will be helpful.

RAHUL SONI
  • 59
  • 1
  • 7
  • Does this answer your question? [Import CSV file into SQL Server](https://stackoverflow.com/questions/15242757/import-csv-file-into-sql-server) – Christian.K Mar 08 '21 at 11:52
  • No Chris - that link doesn't have any way to use BULK INSERT in sqlcmd. – RAHUL SONI Mar 08 '21 at 13:53
  • Have you tried `bcp` command ? – Philippe Mar 08 '21 at 14:38
  • 1
    @RAHULSONI Just write your BULK INSERT statement into a text file, then pass that with the `-i` option to `sqlcmd` (see `sqlcmd -?`). Or, you could even pass the statement literally using the `-Q` option like you did with the "select query" in your example. SQLCMD is not special. It is just a means of passing SQL statements to SQL Server, like any other such tool including SSMS, Azure Data Studio, misc. programming languages + libraries, etc. (That you also need help handling `sqlcmd` options was not apparent from your question to me, sorry.) – Christian.K Mar 09 '21 at 05:46

0 Answers0