Solved

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

Posted on 2014-09-29
6
260 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
  • 3
  • 2
6 Comments
 
LVL 142

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 142

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 142

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now