How to Export SQL table records using a Windows Batch file (.bat) | Ms SQL

preview_player
Показать описание
Export SQL query results with just a click.

In this video i have given a demo on how to Create a Batch File to Export SQL Query Results to a CSV/text file.

sqlcmd is the command
-S   server name. Here, it is A103
-d  database name.
-E   trusted connection (Windows)
-Q   Write your query in quotes:
“select * from report“
-s   column separator
Example : comma  ", "

How to export data from SQL server to Excel - Click below to watch the video

How to import data from excel to SQL server - Click below to watch the video
Рекомендации по теме
Комментарии
Автор

cool man am loving your videos brother

tik-tok
Автор

I need to generate the csv files with the different naming convention at particular location in our server by running task scheduler which will invoke that bat file everyday at particular time . is it possible?

shirshakroy
Автор

Very informative sir! But one question, can this be automated? I mean can this run automatically and send the csv as email attachment to users?

Achinta-lkex
Автор

Does it work if my SQL database needs to connect with the company network / VPN ?

Ivon_vlog
Автор

Can we export with the filename follow the current date?

azlannohara
Автор

Will this work for long blocks of SQL codes too ?

aakriti
Автор

Thank you for the video.
How to save the output file in .xlsx format?

kaushikReddynarra
Автор

I do not have it in columns of excel. It is just one row full of text separated by comma(one column) How did you manage to get the data each in separate column -such instantly ?

MaTiSeK
Автор

But how can we do, if we want the output of multiple tables rather than one table

CHARMINGCHINTU
Автор

Sir pls make a video on upgrade and migration

And pls make another video on expected question on every topic like - backup, restore, DR plans, pt etc.. So that we can prepare easily... Tq

contributorfactz
Автор

is there a way to remove the second line?, ,

matiassquartini
Автор

Can please make a videos on Migration process ..

manasakasam
Автор

Why do we need batch files other than generating files? How common is it?

shurikturan
Автор

where is mistake not run query??
sqlcmd -s DESKTOP-0331Q75 -d TestDB -E -Q "select * from dbo.dept" -s ", " -o "E:\ss.csv"

subhashyadav
welcome to shbcf.ru