?
Solved

Export OSQL Query Result to a Test File

Posted on 2014-09-30
4
Medium Priority
?
209 Views
Last Modified: 2014-09-30
I have the following OSQL command which I need to run.  

My quesiton is how do I export this result into a CSV file?

Use clintrial
SELECT     [PatientID], [PackNo]
FROM       Subject_Treatment_Visits INNER JOIN Trials ON
Subject_Treatment_Visits.TrialID = Trials.TrialID
Where protocoldesc = '00001'
Go
0
Comment
Question by:DHPBilcare
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 40352385
Use Export Data Wizard.
In SSMS right-click on database name, Task, Export Data...
Follow the wizard and in place of table name just paste the query.
0
 

Author Comment

by:DHPBilcare
ID: 40352465
We have a validated system that is using using Microsoft SQL Server Desktop Engine.

Therefroe I need to run the query from the command promt using osql.

I dont have any frontend user interface utility I can use on this server.

Thus I need to add the export command to the query in my first post.
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 40352488
Then use SQLCMD instead of OSQL (old stuff).
sqlcmd -S ServerName -E -i FileName -o OutputFile

Open in new window

0
 
LVL 51

Accepted Solution

by:
Vitor Montalvão earned 2000 total points
ID: 40352498
If you need to configure comma as column separator:
sqlcmd -S ServerName -E -i FileName -o OutputFile -s","

Open in new window

NOTE: FileName is the file with your query but you can substitute it with your full query with -Q option:
sqlcmd -S ServerName -E -Q "SELECT  [PatientID], [PackNo] FROM clintrial.dbo.Subject_Treatment_Visits INNER JOIN clintrial.dbo.Trials ON  Subject_Treatment_Visits.TrialID = Trials.TrialID Where protocoldesc = '00001'" -o OutputFile -s","

Open in new window

0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

764 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