How to Create text file and ammend that file in SQL Server 2005

HI All,
I want to upload some Sql query ouput to .txt file. I have tried using the BCP command.  I am not able to create the .txt file dynamically by running this query.
First create the bcptest.txt in File System and run the query, then its copying the data.
But  I want to create .txt dynamically and wants to append the .txt data instead of overwriting.
EXEC 
 xp_cmdshell
'bcp "SELECT * FROM sysfiles" queryout "C:\bcptest.txt" -T -c -t,'
Ram MSBI Developer

Hi Sebastian,
I have used the query and it is working fine. but, How could i include the headers of the query also in to the Excel Sheet.
RehaanKhan. M
see the method discussed here
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/10/10/export-to-excel-with-column-names.aspx
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • How to create a file in the server?

    Hi,
    I'm making a webservice that has to generate a XML file, sign it using another webservice and return this XML. The problem is that i don't know how to create the file in the server throught webservice.
    I use this code in the webservice to generate the XML and after I return the XML to client in a byte[]
         static void outputDocumentToFile(Document myDocument, String path) {
            //setup this like outputDocument
              try {
                   // XMLOutputter outputter = new XMLOutputter("  ", true);
                   XMLOutputter outputter = new XMLOutputter();
                   //output to a file
                   FileWriter writer = new FileWriter(path);
                   outputter.output(myDocument, writer);
                   writer.close();
              } catch(java.io.IOException e) {
                   e.printStackTrace();
        }But the file is generated in the client-side, how can I generate the file in the server-side?
    Thanks very much.

    Well the File object doesn't create a file it's simply an abstract representation of file and directory pathnames.
    You can try something like this:
    <%
    try
    // get the path to the web server root
    // I read somewhere not to use 'getRealPath' for some reason which I
    // can't seem to remember :S Hopefull someone can enlighten us :)
    String path = application.getRealPath("/project/jsp/demo.txt");
    File file = new File(path);
    PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file)));
    writer.println("Hello World!");
    writer.close();
    catch (Exception e)
    System.err.println(e.getMessage());
    %>
    Hope this helps :)

  • How to open sdf files in SQL server 2012?

    How to open sdf files in SQL server 2012?
     I couldn’t figure out how to open the sdf files in SQL server 2012
     Thank you
     Best
     Jamal

    I don't think it's hard if understood the question properly you can try this I do it most of the time and this might be the solution for you, sometimes minor simple click is a life saver:)
    1. 
    Open SQL Server Management Studio, or if it's running select File -> Connect Object Explorer... and click the
    connect drop down arrow
    2. 
    In the Connect to Server dialog you will see Database Enghine, Analaysis Servie on so on and you go head change Server type to
    SQL Server Compact Edition
    3. 
    From the Database file drop-down as shown below click the drop down arrow and select <
    Browse for more...>
    4. 
    And you will see C:\, D:\, G:\
    drive and so on and open, your SDF file where it is located
    I hope this has been informative for you and good luck
    Please remember to click “Mark as Answer” on the post that has answered your question as it is very relevant to other community members dealing with same problem in seeking the right answer

  • How to save image files into SQL Server?

    Hello, All:
    Does anyone know how to save image files into SQL Server? Does the file type have to be changed first?? Please help me! Thank you!

    You need a BLOB field (usually)... Then you can check this tutorial out:
    http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/exercises/BLOBPut/
    There are other exercises on that site, including one on reading the images back.

  • Error in adding PRIMARY Data file of SQL Server 2005

    Hi Experts,
    I am using SQL 2005 as back end database for SAP ECC6. Due to Space problem in PRD data volume, i have added PRDDATA4.ndf file in SSMS ( SQL Server Management Studio) and saved. But, suddenly i got one more idea and extended the file size of exisiting PRDDATA1.mdf, PRDDATA2.ndf & PRDDATA3.ndf immediately i removed the PRDDATA4.ndf file before starting the service. But, while seeing in SAP using ST04 it showing the PRDDATA4.ndf with error message of file missing. What i have to do now? How can i delete the information showing in ST04. But it is not showing in SSMS.
    Please help how to solve this.
    Regards,
    B.Sudharsan

    Hi,
    Following solution might help you to resolve the issue.
    Solution1:
    Issue happens because universe connection to the Database is not responding and the Data Source Name is not configured to write SQL Server 2005 database.
    Resolution
    Created new DSN connection under SYSTEM DSN to SQL Server 2005 Database.
    Import the universe from the designer.
    Go to File->Parameters.
    Edit Connection.
    On the Database Middleware Page expand SQl Server 2005->Select SQL Server 2005 driver.
    Change the DSN to new DSN connection
    Test the connection.
    Save the Universe and Export it to the repository.
    Solution2:
    I am taking Oracle as an example over here.
    This can be caused when the SQLNET.ora is located in a remote location using mapped drives.
    Resolution
    To resolve,
    check the registry [HKLM\SOFTWARE\ORACLE] you should see a folder called HOME0
    look for any paths that contain a mapped drive partition
    Change the mapped drive letter to a UNC path (
    server\folder)
    Open a command prompt and do a tnsping using the tnsname and verify the location of the SQLNET.ora or TNSNAMES.ora
    If the path is not updated to the new path
    Reboot the server
    Regards,
    Sarbhjeet Kaur

  • How to create text file of report in 10g

    Hi,
    I want to create text file of report in character mode and print that text file, without view it on screen.
    i want to do this in Oracle developer 10g and run this report on web.
    what coading i required to do for this pls. help me.

    Hello,
    Execute the Reports with the parameters MODE=CHARACTER DESTYPE=PRINTER DESNAME=<printer name>
    Regards

  • How to create text file like this?

    I want to create text file like attached file. I thought to create 2 text file: First text file make the headers ( Position, value 0,value 1....) , Second file make the table of data. Then combine them to be third text file. Someone can post other solutions?
    Attachments:
    testdf.txt ‏1 KB
    try_textfile.vi ‏18 KB

    Hi ha noi,
    you don't need 2 intermediate textfiles!
    Just write the header line first, then attach lines containing values...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How to attach .mdf file to sql server 2008 EXPRESS

    I have .mdf files created using SQL SERVER management studio 2012 in another computer and wish to attach the same to SQL SERVER 2008 EXPRESS in another computer. How should I do so? I tried this method :How
    to: Attach a Database File to SQL Server Express but then it shows an error that the database cannot be created due to compatibility issues.
    Msg 948: The database xyz cannot be opened because it is version 706. This server supports version 655 and earlier. A downward path is not supported..
    Any help??

    I have .mdf files created using SQL SERVER management studio 2012 in another computer and wish to attach the same to SQL SERVER 2008 EXPRESS in another computer. How should I do so? I tried this method :How
    to: Attach a Database File to SQL Server Express but then it shows an error that the database cannot be created due to compatibility issues.
    Msg 948: The database xyz cannot be opened because it is version 706. This server supports version 655 and earlier. A downward path is not supported..
    Any help??
    You are trying to attach SQL Server 2012  database files to SQL Server 2008 R2 which is not allowed, you either need to upgrade your SQL Server 2008 to 2012 or alternatively you can generate all scripts from SQL Server 2012 and execute it in SQL Server
    2008 R2.
    You can refer below link to how to generate script.
    http://blog.sqlauthority.com/2012/07/18/sql-server-generate-script-for-schema-and-data-sql-in-sixty-seconds-021-video/
    Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    Praveen Dsa | MCITP - Database Administrator 2008 |
    My Blog | My Page

  • Problem in bulk import of text files in SQL Server

    Hi,
    I am using sql server 2012 x 64 and trying to import some text files (tab/ comma separated) and ms access files in sql server tempdb
    I am trying bulkinsert on text file but it is inserting all data in a single line in sql while in text file I have 1000K lines,
    Then I tried importing other data using openrowset from access file but I am getting following error
    Cannot create an instance of OLE DB provider "MSDASC" for linked server "(null)".
    can any one please provide some assistance . If I am able to upload the data from flat text file then it will be enough as I am getting data in tsv or csv format
    Nitin

    If this is a one-off, I think you should try the import/export wizard in SQL Server Management Studio instead. This may be easier to get working.
    If you want to this import on a regular basis with BULK INSERT, we need to see the CREATE TABLE statement for your table and a sample file. Best if you can upload the file on Skydrive, Dropbox or similar, as the exact bytes matters.
    To connect to an Access database, you use the ACE provider. Never heard of MSDASC before.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How to run Exe file through Sql server agent job

    Hello All
    i have 2 servers 
    1.Application Server
    2.Database server
    Application server has a .exe file so i wanted to run this exe file through SQL server agent job from database server.
    What is the process for run this Exe file 
    Can you plz suggest me step by step process
    Kamal

    While i'm trying to implement this below method
    Step1 : Right Click SQL Server Agent. Select New -> Job. This will open a wizard to schedule a new
    job.
    Step2 : Select Steps from options given on the left side of wizard. This is the main place to set your
    exe\program as a running step. Give some name to this step, Select Operating System (cmdexec) for the Type and give the full path of exe in Text box for Command.
    ex:\\10.11.00.98(your application serverIP)\ch.exe
    Thanks vanchan-Please
    mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
    I got this below error
    Message
    Executed as user:NJROSJ345\SYSTEM. The process could not be created for step1 of job
    (Reason:Access is Denied)The step failed.
    But i have sys admin rights on the both the servers 
    Kamal

  • Open (.sdf) file with SQL server 2005 Management Studio

    In VS2005, I have created a SQL Mobile database, (.sdf).
    Copied that (.sdf) file to Desktop, and when I try to open with SQL Server 2005 management studio, its showing error "make sure the application for the file type (.sdf) is installed."
    How can I open this file with SQL server?
    Regards
    Abinash

    You must install SP2 if using Management Studio Express (http://www.microsoft.com/downloads/details.aspx?familyid=6053C6F8-82C8-479C-B25B-9ACA13141C9E&displaylang=en)Erik Ejlskov Jensen, MCTS: WM App, MCITP: SQL 2008 Dev - http://erikej.blogspot.com
    Please mark as answer, if this was it.

  • How to save landscape print layout for report designed in SQL Server 2005

    How to save page setup for a report wich was designed in SQL Server 2005 RS?  Each time report is previewed, I have to change portrate to landscape orientation and left and right marging from 0,5 to 0,25, to be able to see all fieldas on the report.
    Thanks!

    Hi, Marina;
    Which version of Crystal Reports are you using? Once you set a report to Landscape, and save the report, it should stay that way, unless you change to a different printer.
    Regards,
    Jonathan

  • How to find the list of unused stored procedures in SQL Server 2005?

    Hi,
    I need to find out the list of stored procedures which are not in use.
    I found there is something called "sys.dm_exec_procedure_stats " for SQL server 2008.
    Can you please suggest your ides here to do the same job for SQL server 2005.
    Many Thanks.

    In SQL 2005 there is, sort of. This is query lists the last execution
    time for all SQL modules in a database:
       SELECT object_name(m.object_id), MAX(qs.last_execution_time)
       FROM   sys.sql_modules m
       LEFT   JOIN (sys.dm_exec_query_stats qs
                    CROSS APPLY sys.dm_exec_sql_text (qs.sql_handle) st) 
              ON m.object_id = st.objectid
             AND st.dbid = db_id()
       GROUP  BY object_name(m.object_id)
    But there are tons of caveats. The starting point of this query is
    the dynamic management view dm_exec_query_stats, and the contents is
    per *query plan*. If a stored procedure contains several queries, 
    there are more than one entry for the procedure in dm_exec_query_stats.
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to create Text Tables and Value Tables ?

    Hi all,
    How we can create the Text Table ? Step by Step
    How we can create the Value Table ? Step by Step
    Note : I am not asking about the creation of simple transparant table ...
    Thanks In advance.
    How to use Text tables ?
    With Example Please..
    Thanks in advance.
    Regards.
    Raj

    Hi Raj,
    Table A is a text table of table B if the key of A comprises the key of B and an additional language key field (field of data type LANG). Table A may therefore contain explanatory text in several languages for each key entry of B.
    To link the key entries with the text, text table A must be linked with table B using a foreign key. Key fields of a text table must be selected here for the type of foreign key fields
    If table B is the check table of a field, the existing key entries of table B are displayed as possible input values when the input help (F4) is pressed. The explanatory text (contents of the first character-like non-key-field of text table A) is also displayed in the user's logon language for each key value in table B.
    Only one text table can be created for table B! The system checks this when you attempt to activate a table with text foreign keys for B.
    Regards
    Aneesh.

  • Creating text file from SQL with adding counter in Filename.

    Hi,
    I have a requirement for creating the Tesxt files from Oracle DB which i can achieve by ODISQLUNLOAD.
    But tricky part is that i want have a file name+ counter such that Counter should start with 1 for the first file of the day, then 2,... and reset to 1 for every new date.
    e.g. file0001, file0002,file0003,file0004,.... file0100 and so on for one day.
    But when i will create a file on next day it should be created as again file0001, file0002,file0003,file0004,.... file0100 and so on.
    I may be able to achieve this using some variables but unable to think how could i achieve this.
    Any help would be appreciated.
    Thanks and Regards,
    Mahesh

    Hi Mahesh,
    If the files are loaded as one batch process, for instance, by executing a single package, you could perform a looping function and store the counter as a variable. It would be very similar to the blog post here: https://blogs.oracle.com/dataintegration/entry/using_variables_in_odi_creatin - but you would be using the #counter variable in your filename. Each day that the package is run, the counter starts at 1.
    Hope this will fit your needs.
    Enjoy!
    Michael R.

Maybe you are looking for

  • Annoying dust in a VERY weird place.  Help?

    I got my black iPod nano 4G 8GB at Radioshack on October 18th. Now it's Thanksgiving (Nov. 27), and I noticed some dust in a very strange place. It's in between the glass and the screen itself. I haven't ben able to get it out, and don't know how to

  • Substitute in Line Item Test (BSEG-GSBER)

    Dear all, I have some questions here. For example, in tcode MIRO, we entered the required information. When click on simulate, there will be another line item for Tax Input lines. One of my requirement is, PICK the Business Area field (GSBER) data fo

  • What is the  DBC file name forrmat

    Dear, I want to know what is the file format of DBC file,actually there is multiple dbc file on server and i have a problem,so pelase help me to select the orignal one. --thanks                                                                         

  • HTTPService Error

    When I am activating my HTTPService POST, I am getting this error: [RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #

  • Is it possible to have a Summary section display above every grouped Details section in a report?

    I'm trying to create a report that displays a "Summary" section above every grouped Details section. Is this possible in SSRS?  If so, what is the best way to do it? Thanks!