SQL Server: how to write in the file?

Posted on 2014-08-04
Medium Priority
Last Modified: 2014-08-05
Have to log some data in the file.
Please help with the sql statement to accomplish this.
Question by:quasar_ee
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 400 total points
ID: 40239871
Define 'log', 'some data', and 'the file'.
LVL 23

Assisted Solution

nemws1 earned 400 total points
ID: 40239880
Look into using SQLCMD mode in SSMS.  You want this:

:output "C:\path\to\file"

All queries after this will have their output written to this file instead of the screen.
LVL 15

Accepted Solution

Vikas Garg earned 1200 total points
ID: 40240538

You can write anything to output file

insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=D:\testing.xlsx;','SELECT * FROM [Sheet2$]') 
select * from YoutQuery or Table 

Open in new window


Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question