How do i get a output in CSV of a SQL query executed via SQL Command prompt

Hi All,
I have a question with reference to SQL command prompt. I have a sql query which runs properly and gives proper execution in SQL Management console in GUI.
This report is used to pull the free disk space report of our servers
As i want to schedule it as a report so i want to script it to run via SQL command prompt. I made the script and it works fine if i enter it in SQL command prompt. When i try to extract the output to a CSV File it fails. Below is the details of the command
i am using to query to pull the data. Can anyone help me in getting the output of this query in SQL command prompt.
sqlcmd -W -s , -S Servers FQDN
use operationsmanager
Go
Query:"select Path, InstanceName, SampleValue 
from PerformanceDataAllView pdv with (NOLOCK)
inner join PerformanceCounterView pcv on pdv.performancesourceinternalid = pcv.performancesourceinternalid
inner join BaseManagedEntity bme on pcv.ManagedEntityId = bme.BaseManagedEntityId
where SampleValue < '20' and CounterName='% Free Space' and TimeSampled > '2014-08-06 11:00:00.00'
order by countername, timesampled" -s "," -o "C:\DataSqlCmd.csv"
Go
When i enter the command without the quotes when the query is starting and ending and also without the output command (-s "," -o "C:\DataSqlCmd.csv") it is working and shows the output in the command prompt. Below is the screen shot for
your reference.
Due to security reasons i have to erase the server names:
But when i add the line to extract the output ( -s "," -o "C:\DataSqlCmd.csv") It gives me this error:
The exact command would be:
sqlcmd -W -s , -S CINMLVSCOM01.e2klab.ge.com
use operationsmanager
Go
"select Path, InstanceName, SampleValue 
from PerformanceDataAllView pdv with (NOLOCK)
inner join PerformanceCounterView pcv on pdv.performancesourceinternalid = pcv.performancesourceinternalid
inner join BaseManagedEntity bme on pcv.ManagedEntityId = bme.BaseManagedEntityId
where SampleValue < '20' and CounterName='% Free Space' and TimeSampled > '2014-08-06 11:00:00.00'
order by countername, timesampled" -s "," -o "C:\DataSqlCmd.csv" -h-1
Go
saying the syntax is not correct or some thing as per the below screenshot.
Can any one please help. Below is just the query whi i use to get the output in SQL management studio.
Can any one make a command for the below quer so i can directly execute and test for getting the output.
select Path, InstanceName, SampleValue 
from PerformanceDataAllView pdv with (NOLOCK)
inner join PerformanceCounterView pcv on pdv.performancesourceinternalid = pcv.performancesourceinternalid
inner join BaseManagedEntity bme on pcv.ManagedEntityId = bme.BaseManagedEntityId
where SampleValue < '20' and CounterName='% Free Space' and TimeSampled > '2014-08-06 11:00:00.00'
order by countername, timesampled
Gautam.75801

Can you try the below query?
select Path, InstanceName, SampleValue
from PerformanceDataAllView pdv with (NOLOCK)
inner join PerformanceCounterView pcv on pdv.performancesourceinternalid = pcv.performancesourceinternalid
inner join BaseManagedEntity bme on pcv.ManagedEntityId = bme.BaseManagedEntityId
where SampleValue < 20 and CounterName like '% Free Space' and TimeSampled > '2014-08-06 11:00:00.00'
order by countername, timesampled
-- replace the below query part in the below SQLCMD C:\>SQLCMD -S SERVERNAME -E -d operationsmanager -Q "select * from sys.databases ds with (nolock) where name='master'" -s "," -o "F:\PowerSQL\MyData.csv" -h -1
SQLCMD -S SERVERNAME -E -d OperationsManager -Q "select Path, InstanceName, SampleValue
from PerformanceDataAllView pdv with (NOLOCK)
inner join PerformanceCounterView pcv on pdv.performancesourceinternalid = pcv.performancesourceinternalid
inner join BaseManagedEntity bme on pcv.ManagedEntityId = bme.BaseManagedEntityId
where SampleValue < '20' and CounterName='% Free Space' and TimeSampled > '2014-08-06 11:00:00.00'
order by countername, timesampled" -s "," -o "c:\MyData.csv" -h -1
Refer for the other ways 
http://dba.stackexchange.com/questions/23566/writing-select-result-to-a-csv-file
--Prashanth

Similar Messages

  • How to get Report Output in csv format

    Hi,
    How can i get report Output in csv format, can any one tell me the word used for output type to get output in csv format.
    i have used XLS output type but it opens in excel format.
    conc.addLayout(appCode,concReqCode,"en-US","US",XLS);
    Thanks
    Babu

    Hi Babu,
    Till now in xmlpublisher there is no method to create file in csv format ,you have to create Excel file and then save it in .csv format.Unless and until ur using BI Publisher in which some work around are possible.
    Thanks

  • How can I get the elapse time for execution of a Query for a session

    Hi ,
    How can I get the elapse time for execution of a Query for a session?
    Example - I have a report based on the procedure ,when the user execute that it takes say 3 min. to return rows.
    Is there any possible way to capture this session info. for this particular execution of query along with it's execution elapse time?
    Thanks in advance.

    Hi
    You can use the dbms_utility.get_time tool (gives binary_integer type value).
    1/ Initialize you time and date of beginning :
    v_beginTime := dbms_utility.get_time ;
    2/ Run you procedure...
    3/ Get end-time with :
    v_endTime := dbms_utility.get_time ;
    4/ Thus, calculate elapsed time by difference :
    v_elapsTime := v_endTime - v_beginTime ;
    This will give you time elapsed in of 100th of seconds...
    Then you can format you result to give correct print time.
    Hope it will help you.
    AL

  • Re: How to converting from PL/SQL query to T-SQL query

    How to converting from PL/SQL query to T-SQL query... Its Urgent

    Download the
    SQL Server Migration Assistant for Oracle.  It will convert whole Oracle databases, or single queries or PL/SQL stored procedures.
    With caution that If your database is using Collation which is case sensitive SSMA will not work.SSMA doesnt guarantees 100% for conversion of Queries/stored proc /database if it fails to do so for some queries you will have to do it manually.
    But you can try
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • How we can get the output in excel format for Spawned programs?

    My requirement is to get the excel output for some of the programs (like -Adjustment Register, Applied Receipts Register). I am trying to achieve this by BI Publisher. But these programs has "Spawned" executable. And when I am changing the output type as"XML" I am getting below error in output-
    "XML Parsing Error: syntax error"
    Can anyne suggest how we can get an XML output and then excel output for Spawned programs?
    Thanks in advance,

    Hi,
    If I get it right, you want to convert RXi (Reports Exchange) reports such as Adjustment Register & Applied Receipts Register into XML Publisher. Normally, you need to change the "Output Format" of the program called by the "Spawned" program to 'XML' -- not the "Spawned" program itself.
    However, I believe RXi reports does not support XML output (atleast in 11i). It could only work on Text & Html format. Check on the metalink note below:
    432719.1 - RXi-Only Reports Generate XML Format Exception With No Output Setting the Output Format to XML
    Hope this helps.
    regards,..
    Rownald

  • How can I get the output of graphical mapping as an input to java mapping?

    Hi Experts,
    I am using graphical mapping in my scenario to get an xml at the end, now after this i want to use java mapping and then do encryption on this input. I am using both the mappings in the same interface
    Here the thing is, the input to the java mapping should be the output of the first graphical mapping.
    How can I link the java mapping and graphical mapping so that Ill get the output of the graphical mapping as the input to the java mapping?
    Some pointers to similar kind of implementations is highly appreciated.
    Thanks in advance,
    Thomas
    Edited by: Thomas Varghese on Jan 22, 2009 11:35 AM

    hi,
    the input to the jave mapping will be exaclty the same as if you don't have
    any mapping before that
    the only different is that the input will be XML of the output of the message mapping
    have a look at my blog to see how to combine two mappings:
    /people/michal.krawczyk2/blog/2005/11/01/xi-xml-node-into-a-string-with-graphical-mapping
    that's all
    Regards,
    Michal Krawczyk

  • How do I get console output back on bootup?

    I have several scripts that put status messages to the console on bootup. Now with Greenline it all goes to /var/svc/log/.... which doesn't do me much good.
    How can I get output to the console on bootup back? Note: boot -m verbose doesn't do it.

    If you must do this, change your scripts to output the messages to
    /dev/msglog. A good way to do this is
    my_command | tee /dev/msglogso that the message goes to both the screen and the log.
    (Standard error will only go to the log in the above case.)
    It might be useful to look at some of the method scripts in
    /lib/svc/method for other examples.
    - Stephen

  • How can I get an accurate count of computers (workstations) logged in to my SQL Server database?

    We license our software by number of workstations.
    I have a query that I have used for years to get an accurate count of the workstations logged in to my SQL Server database. For simplicity, all users use the same login name/password. This is built in to the script that attaches to the DB. They
    have access only to that DB with the exception of
    USE [Master] GRANT VIEW SERVER STATE to MyUser
    The query that has been working is below:
    Basically this relies on the mac address (Master.dbo.sysprocesses.net_addre
    SELECT COUNT(Users) AS UserCount FROM (SELECT COUNT(Master.dbo.sysprocesses.hostname) AS Users FROM Master.dbo.sysprocesses LEFT OUTER JOIN Master.dbo.sysdatabases ON Master.dbo.sysdatabases.dbid = Master.dbo.sysprocesses.dbid WHERE (Master.dbo.sysdatabases.name = 'MyDatabase') GROUP BY Master.dbo.sysprocesses.net_address) AS UserCount_1
    ss), since both Workstation names and ip addresses can be duplicated.
    Recently this has stopped working at a number of customers. Suddenly individual workstations are showing multiple net addresses for the same workstation causing a substantial overcount of users. This may be related to SQL Server 2012 - not sure.
    What I need is a very reliable way to get a count of workstations logged in to my database.
    If anyone can tell me why I am suddenly getting multiple net_addresses for each workstation and how to prevent that that would be one possible solution.
    Otherwise if anyone can give me a rock solid way to get a workstation count other than the above that would be great. Our largest customer is 50 users by the way.
    Thanks in advance for any help.
    Kim

    I think your count is getting skewed because of duplicate rows in sysprocesses because of parallelism. Add DISTINCT to your query:
    SELECT COUNT(Users) AS UserCount
    FROM
    ( SELECT COUNT(DISTINCT Master.dbo.sysprocesses.hostname) AS Users
    FROM Master.dbo.sysprocesses LEFT OUTER JOIN Master.dbo.sysdatabases
    ON Master.dbo.sysdatabases.dbid = Master.dbo.sysprocesses.dbid
    WHERE (Master.dbo.sysdatabases.name = 'MyDatabase'
    GROUP BY Master.dbo.sysprocesses.net_address) AS UserCount_1
    Satish Kartan www.sqlfood.com

  • How can i track the all sql/query executed from application

    How we can track all sql/query that has executed or being executing on oracle database server 10g r2.
    regards
    Prabhaker

    select s.sid,
           s.status,
           s.process,
           s.osuser,
           a.sql_text,
           p.program
    from v$session s,
         v$sqlarea a,
         v$process p
    where s.sql_hash_value = a.hash_value
      and s.sql_address    = a.address
      and s.paddr          = p.addr
      and s.schemaname     = '&1'
      and s.status         = 'ACTIVE'

  • How can i get belo output for smartform

    i want output like this for servise tax
    item at 50 servise tax 10.20%
    but i m getting output like this
    item at 50 servise tax 10.00%
    if ( t_komv-kschl = 'JSRE' OR t_komv-kschl = 'JSRF' OR
    t_komv-kschl = 'JSER' OR t_komv-kschl = 'JSVD' OR
    t_komv-kschl = 'JSRC' OR t_komv-kschl = 'JSRD') .
    IF t_komv-kschl = 'JSRE'.
        g_percentage = t_komv-kbetr / 10.
      ELSE.
        g_percentage1 = t_komv-kbetr / 10.
    ENDIF.
    add t_komv-kwert to l_stax-amt.
        l_stax-item_no = t_komv-kposn.
        l_stax-amt = t_komv-kwert.
        l_stax-per = t_komv-kbetr / 10.
        append l_stax to it_stax.
    ENDIF.
    IF ( ( g_percentage IS NOT INITIAL AND
    g_percentage1 IS NOT INITIAL ) AND
    ( t_komv-kschl = 'JSRE' OR t_komv-kschl = 'JSRF' OR
    t_komv-kschl = 'JSER' OR t_komv-kschl = 'JSVD' OR
    t_komv-kschl = 'JSRC' OR t_komv-kschl = 'JSRD') ).
    g_mul = g_percentage * g_percentage1.
    g_percentage3 = g_percentage + ( g_mul / 100 ).
    l_stax-per = g_percentage3.
    append l_stax to it_stax.
    clear : g_percentage, g_percentage1.
    ENDIF.
    thanks in advanced.

    Hi,
    You take Tax as
    Data: Tax type P(c.2).
    Then you will get as per your requirement.
    Thannks,
    Rani.

  • How do I get the output of Audition 3.0 to go to my speakers?

    I am running Audition 3.0 on a PC with Windows 7 Home Premium.  This may not be the proper place for this question, but I was not able to put it on the Adobe Audition 3.0 and earlier forum.
    I am trying to record cassettes into Audition via a Behringer UFO202 USB device.  I plug in the USB and my computer sees it and I can hear via the headphone output that it is playing.  I go to the Windows Recording Mixer and it indicates that a USB audio device is working and I can see it recording into Audition.  However, when I turn on my speakers, nothing comes out.  When I play I-Tunes or sounds off my internet browser, I hear what I play, but I can't hear anything off Audition.
    I am also using a HT Omega Sound Card.
    I figure it is something that is not checked in some window someplace, but i can't figure out what.
    Any help would be greatly appreciated.
    Thank you.

    New Orleans Audition User wrote:
    Speakers are connected to the audio outputs on the front of my
    computer.  The connection is a stereo headphone connection.  I can hear
    sound through them for other applications (web browsers etc.) that my
    computer is running.
    Ah, that's what I thought. The problem with using ASIO is that it can only work with one hardware device at a time, so if you install the ASIO driver for the Behringer, then it's the Behringer that you have to connect an amp and speakers to.
    Unless, of course, you use a converter that will connect ASIO-only software (Audition) to the standard windows audio system, using Windows drivers. Guess what? There's a free one that does just this, and it will let you use more than one sound device at a time (albeit with higher latency). It's called ASIO4ALL, and it's dead easy to find with a Google search. If you install it, the chances are that it will see both your Behringer and also the internal sound device in its list of available devices, so you should be able to have it available for replay purposes.

  • How do I get iTunes output through USB port ?

    How do I play iTunes through USB Port ?

    Have you updated both Airport Express units to the latest firmware?

  • How do I get audio output from a labview program

    We are modifying an existing labview program that reads data from a BNC-2140 DSA and displays as a graph. We want to be able to stream audio in audible range instead of a graphical display. Is there a VI available that can create audio? If not, how can I go about creating one?
    Thank you

    Hey Lost-
    There is a wonderful document on our external website that groups our knowledge on using sound with LabVIEW.
    Under the LabVIEW Resource Library (http://zone.ni.com/libraries/) choose -> LabVIEW -> Advanced Programming Techniques -> Using Sound.
    This page lists over 5 examples for playing sounds with LabVIEW through WAV, MP3, and other formats. Streaming audio might be tough, depending on your processor. It might be hard to translate your input into a format LabVIEW can play. I am not sure what sound format that input data you refer to would be. This will be a good starting point. Also, I have heard of a Microsoft ActiveX control, DirectShow, that might help you. I have not worked with this guy, but I would check into it at Microsoft's site -> www.msdn.
    microsoft.com.
    Post again if you have follow-up questions.
    ben schulte
    national instruments

  • How can i get an xbox 360 to connect to my time capsule via WIRED connection?

    I have a Time Capsule and i need to connect my xbox 360 to it because my stepdad has the network in this house set up crazily. He gets mad if i ask him to change anything because it is how he wants it and it works with EVERYTHING ELSE. I do not have a wireless adapter so i need to connect the xbox to my time capsule via a wired connection
    Thanks =]

    Here is what I would look into.
    Use iCloud and photo stream to upload pictures taken with the iPad.
    Find a remote log in utility, or web based app to then remote to your computer.
    Download the files from photo stream to your time capsule.
    As far as recommending a remote log in utility. I have not experience in that area and would need to do research my self.

  • How can I get rid of Babylon that took over my home page via Firefox?

    A site called Babylon took over my home page among other things last week. Your advice via email to get Firefox from someone else who has it wasn't feasible. Neither was Riva uninstaller which you recommended. This appears to be an attack on Firefox and although I got rid of most of Babylon, it still dominates my home page. I love Firefox but this is bad news. I need it fixed.
    Thank you for your time.

    Sorry, the person replying to your previous question ( https://support.mozilla.org/en-US/questions/910349?s=&r=1&e=sph&as=s ) is a new poster here and did not offer the best advice.
    #Remove Babylon from your system:
    #*See --> http://www.ehow.com/how_5545010_uninstall-babylon.html
    #*Also see --> http://support.mozilla.org/en-US/kb/Uninstalling+add-ons
    #*Also see --> http://support.mozilla.org/en-US/kb/Cannot%20uninstall%20an%20add-on
    #*Also see --> http://kb.mozillazine.org/Uninstalling_toolbars
    #Reset your home page (if the Babylon search page is displayed when starting Firefox): http://support.mozilla.org/en-US/kb/How+to+set+the+home+page
    #*You can reset to the default by clicking "Restore to default" on Options > General > Startup > Home page. Be sure to set "When Firefox starts" to "Show my home page" on that same panel.
    #Reset your Location Bar search engine (if typing a few words in the URL/Location Bar takes you to Babylon search):
    #*type '''''about:config''''' in your Location Bar, like typing a web site address, and press the Enter key
    #*ignore warning and choose to continue
    #*in Filter, type '''''keyword.URL'''''
    #*in lower part of screen, if it is '''bold''' and shows "'''user set'''", right-click keyword.URL and choose "Reset"
    #*in Filter, type '''''babylon'''''
    #*any items in lower part of screen in '''bold''' and showing "'''user set'''", right-click and choose "Reset"
    #*close about:config tab
    #*See:
    #**http://kb.mozillazine.org/About:config
    #**http://kb.mozillazine.org/Location_Bar_search#Location_Bar_search_.28external_-_search_engine.29
    #**http://kb.mozillazine.org/Keyword.url
    #**http://www.techrena.net/computers/address-bar-search-provider-firefox/
    #If Babylon is shown in your Search Bar and you want to remove it:
    #*https://support.mozilla.org/en-US/kb/Search%20bar
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''
    Not related to your question, but...
    You may need to update some plug-ins. Check your plug-ins and update as necessary:
    *Plug-in check --> http://www.mozilla.org/en-US/plugincheck/
    *Adobe Shockwave for Director Netscape plug-in: [https://support.mozilla.org/en-US/kb/Using%20the%20Shockwave%20plugin%20with%20Firefox#w_installing-shockwave Installing ('''''or Updating''''') the Shockwave plugin with Firefox]
    *'''''Adobe PDF Plug-In For Firefox and Netscape''''': [https://support.mozilla.org/en-US/kb/Using%20the%20Adobe%20Reader%20plugin%20with%20Firefox#w_installing-and-updating-adobe-reader Installing/Updating Adobe Reader in Firefox]
    *'''''Shockwave Flash''''' (Adobe Flash or Flash): [https://support.mozilla.org/en-US/kb/Managing%20the%20Flash%20plugin#w_updating-flash Updating Flash in Firefox]
    *'''''Next Generation Java Plug-in for Mozilla browser'''''s: [https://support.mozilla.org/en-US/kb/Using%20the%20Java%20plugin%20with%20Firefox#w_installing-or-updating-java Installing or Updating Java in Firefox]

Maybe you are looking for

  • How to set null value for a date column using database adapter

    Hello, I have a table wih 3 columns (id NUMBER, modified_on DATE contentText VARCHAR2) I have a row wih theses values (1, 20/03/2010 16:30, 'coucou') I want use a DB adapter in a BPEL process to change the value of column modified_on to (null). I'm u

  • How to send TTL output AND acquire AI voltage data using USB-6211

    Hello, I am relatively new to Labview, so please bear with me.  I have a research application involving 2 pressure transducers and a high-speed camera.  I wish to acquire analog voltage data from the 2 pressure transducers.  However, at the start of

  • Oracle enterperise manager start error

    I have oracle database 11GR2 on windows 7 when i want to start enterprise manager , the error in below is shown : Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.   C:\Users\SHOJAIE>emctl start dbcon

  • Converting time one format to another

    Hi Friends, I have a small problem in converting time.. Actually In my program i am getting time like this ' 080000 ' but that should be converted to 8.00 hrs if i give time is ' 085215 ' means 8 hrs 52 min 15 sec so...it should be changes to 8.52.15

  • Jdbc connection in EJB using wsad 5.0

    Hi, I want to develop a small application using Ejbs by using oracle 9i as D/b, wsad 5.0 as app server . The problem is i am not able to connect to oracle database in WSAD. What i am doing is i have installed Oracle 9i in my system and has given the