How to Export Query result to CSV file by Using Sql Script

RAMA KRISHNA MANDALAPU 0 Reputation points
2023-03-06T17:49:43.96+00:00

Hi,

I need to store Sql query result to csv file in a given path.
I need to this task in SQL Agent.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,642 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Erland Sommarskog 100.8K Reputation points MVP
    2023-03-06T22:26:36.22+00:00

    Check out this blog post from Luca Zavarelli on how to do it from PowerShell: https://towardsdatascience.com/extracting-data-from-azure-sql-server-huge-tables-in-rfc-4180-compliant-csv-files-1cb09a7a0883

    Might be less heavy artillery than SSIS.

    1 person found this answer helpful.
    0 comments No comments

  2. Yitzhak Khabinsky 24,936 Reputation points
    2023-03-06T18:37:15.0933333+00:00

  3. PercyTang-MSFT 12,426 Reputation points Microsoft Vendor
    2023-03-07T01:59:56.3066667+00:00

    Hi @RAMA KRISHNA MANDALAPU

    In addition to the above two answers, you can also refer to this link. There are a lot of targeted methods inside.

    https://stackoverflow.com/questions/3169220/export-query-result-to-csv-file-in-sql-server-2008

    Best regards,

    Percy Tang


    If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments