Solved

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

Posted on 2014-09-29
6
275 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 500 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

726 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