Solved

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

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

690 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