BCP queryout -w generating wrong CSV File

I'm trying to generate a CSV file with BCP. My problem is that I have some NVARCHAR columns so I must use the parameter -w for the bcp utility. So, the CSV file generated is opening in a single column in EXCEL. If I create a new text file copy the content
of the CSV generated and paste in the new file and then change its type to CSV it works and open the content spread in different columns. Has someone seen it before? Thanks
SET @File = 'MyQuery.csv'
set @SQL = 'bcp "SELECT FirstName, LastName, DwellingName FROM Table" queryout "' + + '" -w -t "," -T -S '+ convert(varchar,@@ServerName)
exec master..xp_cmdshell @SQL

Hi,
I agree with you. It seems the text was attached with some text attribute when generated by BCP. When I copy the content to Notepad, I notice each rows were enclosed in double quotes. Image:
The double quotes make Excel think it is a unit. If I remove the double quotes and import the data to Excel, it will copy the text to separate columns.
1. On the Data tab, in the Get External Data group, click From Text. And follow the instructions in the
Text Import Wizard.
2. Under Original data type, choose Delimited, click Next.
3. Select Tab. I can review the data in the bottom of the dialog box. Then, Next.
Another option is to query the results to file and save it as csv file. Use the Text Import Wizard to import the csv file into Excel. Select Space option in the step 3.
Thanks.
Tracy Cai
TechNet Community Support
Hi Tracy,
I've found a solution for my problem:
I've used the -CACP to generate the CSV file ANSI Encoded and it works!!!
Now my command looks like: 
SET @File = 'MyQuery.csv'
set @SQL = 'bcp "SELECT FirstName, LastName, DwellingName FROM Table" queryout "' + + '" -c -CACP -t "," -T -S '+ convert(varchar,@@ServerName)
exec master..xp_cmdshell @SQL

Similar Messages

  • Issue while generating a CSV file through Oracle.

    Hi,
    I am generating a CSV file using oracle stored procedure.
    In an Oracle procedure I need to create a CSV file, which contains the data of a select query, and then emailing this file. Problem is that one of the field contains comma eg ('ABC,DE'). Now in the CSV file 'ABC' is shown in the one cell and 'DE' is shifted to the adjacent cell which is not required..
    Thanks.

    Hi Welcome,
    If you data contains comma then make ~ as your delimeter.
    or repalce all the commas form your data.
    select replace(column_name,',','') from table_name; /* before writing to the file */Regards,
    Bhushan

  • Column heading is not coming while generating a .csv file from .sql file

    Hi all,
    Now since I am able to generate a .csv file by executing my .sql file, the column heading is missing in that. Please advise. I have used the following parameters in my query:
    set linesize 1000
    set colsep ','
    set echo off
    set feedback off
    set pagesize 0
    set trimspool on
    spool /path/file.csv
    select ...... from .... where .....;
    spool off
    exit

    set pagesize 0 <-- your problem
    you must set it into a high value (max value 50000)
    see:
    SQL> select * from dual;
    D
    X
    SQL> set pagesize 0
    SQL> select * from dual;
    X
    SQL> set pagesize 50000
    SQL> select * from dual;
    D
    X

  • How get output generated as csv file  by reading  by buffered reader and wr

    how get output generated as csv file by reading by buffered reader and writer

    String file_location = "C\temp\csv.txt");
    try {
         URL fileURL = getClass().getResource(file_location);
         if (fileURL != null){
              BufferedReader br = new BufferedReader(new InputStreamReader(fileURL.openStream()));
              String s = br.readLine();
              while (s != null)  {
                   if (!s.equals ("")) {
                        System.out.println(s);
                   s = br.readLine();
              br.close();
         else {
              // error
    catch (IOException ex){ex.printStackTrace();}rykk
    Message was edited by: a dummy
    rykk.

  • How to delete duplicate data that generated from csv file??

    The thing i have done is that i red all the data in the csv file without removing the duplicate data and display it.. For where i should have a known number of index (about 13), my main file should have 13 records no duplicate values. and how can my Java program update the corresponding record in the main file each time an index is updated??
    Hope somebody can assist me on this..it would be really helpful for me...
    Thank you.
    -Rao-
    Edited by: reemarao on Apr 1, 2010 3:58 AM

    Hi Sudhir,
    In case you have edit access in your system carry out the following procedure:
    1. Create an export datasource on your cube.
    2. Now create the update rules to your cube using the datamart Infosource.
    3. In the update rules multiply all the key figures by
    -1.
    4. Now create an infopackage and give the request id of the duplicate request as selection.
    5. Load the datamart request and do the data validation.
    If you do not ahve edit access there is no other alternative you would have to delete all the data and reconstruct the requests that you need.
    Bye
    Dinesh

  • AIA 3.1 service constructor generates wrong AIAServiceConfigurationP file

    Hi
    When I use the service constructor to generate a ABCS with CAVS it generates a wrong AIAServiceConfigurationProperties.xml file.
    the AIAServiceConfiguration element is not included / generatad ,
    this has as result that the AIAConfigurationProperties.xml file does not contain this entry so the xsl for the ebm header crashes
    thanks

    Hi,
    Check the Object Name field in Step 4 of Service Constructor. Ensure it is PurchaseOrderList, If it was jus PurchaseOrder you edit and append List to it.
    After Finish, your Prov ABCS will be named as CreatePurchaseOrderListEbizProvABCSImpl.
    Regards,
    Rahul

  • Brackets in csv file generated by BI Broadcaster

    Hi all,
    Here is my problem:
    I generate a csv file using the BI broadcaster (BI 7.0). It works, but each field of the file are between brackets.
    i.e:
    "13.11.2008";"63417440";" EDT";"101";"780032";"1452";"8EAE";"1.141,000"
    instead of:
    13.11.2008;63417440;EDT;101;780032;1452;8EAE;1.141,000
    Do you know why? Is there a set-up to avoid these brackets?
    Thanks for your help.
    Stephane

    Hi,
    To my knowledge for example,
    take a flat file and then save it in CSV format you can see  the text file  in the below format as
    17,"SR-30","PSO-ABM Wise Ranking Report"
    18,"SR-18 (SR-72)","PSO WISE SALES RECORD"
    19,"SR-27 ","Ranking Report Percentage Wise"
    20,"SR-28","ZM WISE RANKING (RUPEE WISE"
    21,"SR-32","RM WISE PRODUCTIVITY RANKING "
    22,"SR-11","Field Performance History "
    23,"SR-24","SALES TO STOCKIST "
    24,"SR-7-Z","MONTHLY ACTUAL UNITS SOLD EXCLUDING BONUS -ZM WISE"
    This is the actual format for the CSv file.If you try changing it then you will get an error.
    Go to data source->right click on display->go to extraction tab->you can see data format click on it you will get the formats as fixed lenth,CSV
    Under that you can see data seperator there csv allow either comma(,) or (
    under that you can see escape sign that is (")
    these are the actual CSV formats.
    Try changing them and give your own format you will get an error.
    I hope it will help you.
    If the above is wrong correct me.

  • How to generate report output in csv file and send it to user email inbox

    Hi All,
    We have requiremnt to generate the csv file from the report (Bex query)automatically and need to send that file automatically to user email address every week.
    It should be done automatically and one more thing the file name should contain that particuar date
    for example if we generate file automatically today the file name should be like below.
    US_04_15_2009.CSV
    Any one have any ideas?
    Regards,
    Sirisha

    Hi Arun Varadarajan.
    Thanks for your reply.We are in BI 7.0.Can you tell me how to  broadcast the query as CSV.Please let me know  if there is any possiblity to display or change the file name dynamically  based on system date.
    Regards,
    Sirisha
    Edited by: sirisha Nekkanti on Apr 16, 2009 4:08 AM

  • Generating .csv file with the datas from the database

    Hi Java experts,
    Ihave a current assignment to generate a .CSV file using java getting values from database. The output CSV file may have more than one row and each row should have a end of line delimiter. Any help in giving a template for generating a CSV file accessing from database is greatly appreciated.

    Ihave a current assignment to generate a .CSV file
    using java getting values from database.well, I hope you learn something doing it yourself...
    The output
    CSV file may have more than one row and each row
    should have a end of line delimiter. Any help in
    giving a template for generating a CSV file accessing
    from database is greatly appreciated.How about looking for a JDBC and a file/print stream tutorial?

  • Generating CSV file using java/ stored proc

    Hi Folks,
    I am using Oracle 11g DB
    My requirement is that I have to generate a CSV file which has customer details. Each value that is comma separated comes from different set of SQL queries. I want to write a stored procedure along with java code to acieve this. How do I go about it? Should I return multiple cursors from my stored proc and iterate from the java side to create the CSV file? Any other suggestions?
    Thanks
    Vishal

    >
    I am using Oracle 11g DB
    My requirement is that I have to generate a CSV file which has customer details. Each value that is comma separated comes from different set of SQL queries. I want to write a stored procedure along with java code to acieve this. How do I go about it? Should I return multiple cursors from my stored proc and iterate from the java side to create the CSV file? Any other suggestions?
    >
    Other suggestions? Yes - don't reinvent the wheel - it has already been created.
    1. Tom already wrote such a proc and published it many years ago. See this AskTom thread
    http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:235814350980
    2. See BluShadow's link from the '5. How do I read or write an Excel file?' question in the FAQ at the top of the sql and pl/sql forum
    SQL and PL/SQL FAQ
    3. Use a sql developer query like 'select /*csv*/ * from emp
    4. Search the sql and pl/sql forum for csv and use of the many threads that already answer this.

  • PL/SQL-Generate CSV file

    I was told I was able to generate out a CSV file through UTL_FILE method. Can someone provide the skeleton of how should I create it in PL/SQL?
    I tried google search but it only says in words and not code itself.
    I have this PL/SQL that I will want to generate a CSV file.
    SET SERVEROUTPUT ON;
    SET TIMING ON;
    DECLARE
        CURSOR C1
        IS
        select balance from contract ;
    BEGIN
        FOR i IN C1 LOOP
    IF i.balance <> '0' THEN
          DBMS_OUTPUT.PUT_LINE('Amount is not 0 '); 
    I will like to put the statement 'Amount is not 0 ' in a CSV file here
         else
         DBMS_OUTPUT.PUT_LINE('Amount is 0 '); 
         END IF;
         end loop;
    END;
    /How am I suppose to do this?
    Edited by: JoannaLee on Aug 26, 2008 7:14 PM

    Your question is a bit confusing. In your subject line, and again in your question, you talk about generating a CSV file. That is a file of comma-separated values (hence the acryonym). But your question seems to be asking about generating a file with a sentence in it-- that would be a flat file but not a CSV file.
    The links that were provided show you exactly how to generate a CSV file based on an arbitrary query.
    If you are not looking to generate a CSV file, and instead you just want to generate a flat file to which you can write data, you'd just need to use the UTL_FILE package. Assuming you're on a recent version of Oracle, you would need to create a directory object, i.e.
    CREATE DIRECTORY directory_name AS 'path_to_directory_on_database_server'Then you'd grant privileges on that directory object to whatever user will own the procedure that wants to write to the directory
    GRANT read, write ON directory_name TO some_userIn your code, you'd just need to open the file and write to it
    DECLARE
      l_file utl_file.file_type;
    BEGIN
      l_file := utl_file.fopen( 'DIRECTORY_NAME', 'name_of_file', 'w' );
      <<Other code>>
      utf_file.put_line( l_file, 'String you want to write to the file' );
      <<More code>>
      utl_file.fclose( l_file );
    END;Justin

  • Issue in conversion of output file from alv to csv file using GUI_DOWNLOAD

    hi,
    I am using GUI_DOWNLOAD to convert the internal table that am getting as the output of an alv into a csv(comma separated file) file.I am using the following code but its not generating a csv file instead it is generating a normal space delimited file.
    The code is as follows:
    data : lv_fname type string.
    lv_fname = 'C:\Users\pratyusha_tripathi\Desktop\status8.csv'. " Provide the file path & file name with CSV extention
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    filename = lv_fname " File name including path, give CSV as extention of the file
    FILETYPE = 'DAT'
    WRITE_FIELD_SEPARATOR = '#' " Provide comma as separator
    tables
    data_tab = ITAB " Pass the Output internal table
    FIELDNAMES =
    EXCEPTIONS
    OTHERS = 22
    IF sy-subrc 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Kindly let me know what changes can be made to make my code work.Also can GUI_download be used for batch processing and storing the output in application server?
    Thanks ,
    Pratyusha

    Hi,
    the short text description for WRITE_FIELD_SEPARATOR is "Separate Columns by Tabs in Case of ASCII Download", so why do you expect a comma?
    Try SAP_CONVERT_TO_CSV_FORMAT and then download.
    And no, GUI_DOWNLOAD is only for download via SAP GUI to a users computer.
    Best regards,
    Oliver

  • Creation of CSV file on client machine with data from forms

    Hi,
    My requirement is to generate a CSV file(or .XLS) on the client machine ie local drive with the details shown in a form.
    Oracle version -
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE 11.1.0.7.0 Production
    TNS for Solaris: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production.
    I have searched the web for last couple of days and got to know that TEXT_IO is to be used to generate files on client machine. However, when I tried TEXT_IO, it was not able to generate the file on client rather it was able to generate on database server. After further browsing on this, there was a link which said that we need to use CLIENT_TEXT_IO to generate file on client side. For this, i was required to subclass the webutil.pll which i did and corrected the code to use CLIENT_TEXT_IO. The form was unable to compile and was not able to find "webutil_core" package.
    I am very confused with the disparity in the information available on the web as in what to use to generate a file on client side. If anyone has use it in the past, can he/she please detail what to use to get things sorted.
    Thanks,
    R

    Oracle version - Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE 11.1.0.7.0 Production
    TNS for Solaris: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production. >
    So, what is your FORMS version. This is more important than your database version.
    My requirement is to generate a CSV file(or .XLS) on the client machine ie local drive with the details shown in a form. Depending on your Forms version, you would use TEXT_IO (if Forms 6i running in Client/Server mode) or WebUtil (if Forms 9i or higher).
    I'm going to guess that you are at least using Oracle Forms 9i since you stated that your attempt at using TEXT_IO produced a file on the DB server.
    There is more to using WebUtil than just attaching the WEBUTIL.PLL. If you had performed a simple search of the Forms Help System would have found numerous WebUtil topics to include: Introduction to WebUtil, Configuring WebUtil, Using WebUtil in Your Applications and the WebUtil User's Guide. If you have Oracle Forms release 10g or higher, WebUtil is included when you installed Forms, however, you do need to configure your installation to use WebUtil and you must download the Java COM Bridge (jacob.jar) from Source Forge. Take a look at the Configuring WebUtil Forms Help topic to find out which version of the Java COM Bridge you will need to download.
    After you have successfully configured WebUtil, take a look at the Using WebUtil in Your Applications topic to find out how to implement WebUtil in a form.
    Searching the Internet for answers is great, but don't forget the look at the Forms Help System because the majority of your questions can be answered there. :)
    Lastly, configuration of WebUtil is primarily done on your Application Server (AS). However, if you plan to perform preliminary runtime testing by running your Form from the Forms Builder, then you will configure your local runtime to support WebUtil as well as configure your AS. The steps are exactly the same. A common mis-step is to skip a step during the configuration because you don't think the step applies. Take a look at the Forms Help Runtime Setup Checklist topic for a list of step you need to complete in order to enable WebUtil.
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • Generation of CSV file

    Hi
    I am looking for the best approach to generate a CSV File extract from a database
    result set. I am currently using Workshop 8.1. Are there any controls that enables
    to perform this task.
    Thanks for your ideas
    Chrs
    Raj

    Hi
    I am looking for the best approach to generate a CSV File extract from a database
    result set. I am currently using Workshop 8.1. Are there any controls that enables
    to perform this task.
    Thanks for your ideas
    Chrs
    Raj

  • How to change an existing line item in CCM catalog using CSV file?

    Dear All,
    We are using SRM5.0 and CCM 2.0
    We have uploaded the material and service master to CCM as supplier catalog from R/3.
    The initial Upload was doen successfully.
    My query is how to reflect the delta changes in CCM happening in R/3?
    If I can generate a CSV file with all those items wich has been changed (Changes can be in description, Plant, status etc) and upload the same file in CCM, will it update the existing line in CCM or create a new line item?
    How do i update an existing line item in CCM catalog using a CSV file?
    Thanks
    Abhishek

    Hi Atul,
    I am using CCM 2.0 and SRM 5.0 (EBP5.5).
    We are not using XI, so i guess we cant use the program "/ccm/file_upload".
    we have migrated the product master data from R/3.
    We have developed a report which takes product category as input and gives out flat file in csv format containg all the items in that prod category.
    Then we upload the file in CCM by logging thro the brpwser.
    Similarly, i can develop another program which will give me a CSV file foll all those items changed in R/3 in a day.
    Then we can upload that file in CCM.
    But i have doubt if it will update the existing items in catalog.
    Hope I could make myself clear.
    Thanks
    Abhishek

Maybe you are looking for

  • How do I create a automatic second page with different layout settings?

    Hi there, I want to create a business letter template with a different second page. I already managed to create a different layout on page nr two, but whenever I write a letter with this template and I reach the end of page one, pages creates a thrid

  • I want to kill home sharing

    I originally turned on home sharing on my desktop when I rebuilt my laptop so that I could share the music without it having to be in both places.  When I realized that creating a playlist on the laptop copies those songs locally anyway, I decided to

  • How much does an iPod shuffle hold?

    Earlier today I found an iPod shuffle (1GB 2nd gen silver) on 5th Avenue in New York on my way to the Apple Store. I was wondering how many songs it holds total? It works and everything too!

  • Attach ADOBE form to transaction code.

    Dear All,             I have a solution to be implemented wherein I need to attach an offline Interactive Abobe form to a transaction code. The scenario is the end user has access to this custom transaction code which when he executes should open the

  • I have lost Safari from my iphone. How do I reinstall it?

    I have somehow lost Safari from my iPhone. Can anyone help?