?
Solved

How to run an SQL Query via the Command prompt for OSQL

Posted on 2014-09-29
6
Medium Priority
?
300 Views
Last Modified: 2014-09-30
We have a validated system that is using using Microsoft SQL Server Desktop Engine.

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

I just need to understand how to frame the following, line by line when entering into osql.

SELECT     [PatientID], [PackID]
FROM         Patient_Visit_Treatments INNER JOIN
                      Trials_History ON Patient_Visit_Treatments.TrialID = Trials_History.MAPSEC_ID AND Patient_Visit_Treatments.MAPSEC_Version = Trials_History.MAPSEC_Version
                       Where protocoldesc = '00000000001'
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
  • 2
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 40349655
please do not use osql, but sqlcmd command line tool:
http://msdn.microsoft.com/en-us/library/ms162773.aspx

however, I don't understand the question in regards to "framing"?
I presume it's about the "long" sql, you might consider having the sql stored inside a file...
0
 

Author Comment

by:DHPBilcare
ID: 40349688
How do I execute the query via a txt file?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40349704
-i input_file
0
 

Author Comment

by:DHPBilcare
ID: 40350266
Sorry I am new to this.  

Can you give me an example of the DOS command to run a query from a txt file and extracting the result into another txt file?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40352116
sorry, but all of that is shown in the linked page...
sqlcmd -i c:\file.sql -o c:\output.txt
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

762 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