Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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.
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

770 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