Exporting list of tables to text files?

Anyone have solution for exporting list of SQL tables to text files?
My goal is to have a flexible/dynamic way to export sql tables to text files that is executed via a sql job. I plan on having a configuration table that has sqltablename, fieldstoexclude (maybe fieldstoinclude - not decided), path, filename, includeheader,
delimiter. So the SSIS package will query the configuration table and that will be the loop. One text file for each configuraton.tablename row.
Does anyone have an already built solution that they can share? I have seen some with vb script and am not opposed, but would like to have a strictly SSIS package that uses SQL queries for the solution.

Try using this as your query (Remember to set the database you want to use first:
DECLARE @tableBuilder TABLE (dSQL VARCHAR(MAX))
DECLARE @tableString VARCHAR(100), @newTableString VARCHAR(100), @columnString VARCHAR(MAX), @dSQL VARCHAR(MAX) = ''
DECLARE tableBuilder CURSOR FOR
SELECT
'CREATE TABLE '+d.name+'.'+t.name ,
c.name + ' ' +
CASE
WHEN st.NAME IN ('float','image','text','uniqueidentifier','date','time','datetime2','datetimeoffset','tinyint','smallint','int','smalldatetime','real','money','datetime','smallmoney','bigint','bit','hierarchyid','timestamp','xml','geometry','geography','sql_variant','sysname') THEN st.name
WHEN st.name IN ('decimal','numeric') THEN st.name + '(' + CONVERT(VARCHAR,c.precision) + ',' + CONVERT(VARCHAR,c.scale) + ')'
WHEN st.name IN ('nvarchar','nchar','char','varbinary','varchar','binary','ntext') THEN st.name + '(' + CONVERT(VARCHAR,c.max_length) +')'
END + ','+ char(13)+CHAR(10)
FROM sys.tables t
LEFT OUTER JOIN sys.extended_properties ep
ON t.object_id = ep.major_ID
AND ep.name = 'microsoft_database_tools_support'
INNER JOIN sys.columns c
ON t.object_id = c.object_id
INNER JOIN sys.systypes st
ON c.system_type_id = st.xtype
INNER JOIN sys.databases d
ON DB_ID() = d.database_id
WHERE ep.name IS NULL AND is_ms_shipped = 0
ORDER BY t.name, c.column_id
OPEN tableBuilder
FETCH tableBuilder INTO @tableString, @columnString
WHILE @@FETCH_STATUS <> -1
BEGIN
IF @tableString <> @newTableString
BEGIN
SET @dSQL = @newTableString + char(13)+CHAR(10) + ' (' + char(13)+CHAR(10) +LEFT(@dSQL,LEN(@dSQL)-3) + char(13)+CHAR(10) + ' )'
INSERT INTO @tableBuilder ( dSQL ) VALUES (@dSQL)
SET @dSQL = ''
END
SET @dSQL = @dSQL + ' ' + @columnString
SET @newTableString = @tableString
FETCH tableBuilder INTO @tableString, @columnString
END
CLOSE tableBuilder
DEALLOCATE tableBuilder
SELECT * FROM @tableBuilder
Export the results of that as you like.

Similar Messages

  • How to write from a linked list collection to a text file.

    Hi,
    I want to write my data in linked list collection to a text file.
    the following is the code of my linked list. how do i write it
    Iwant the data to be comma separated while writing it to a text file.
    please help.
    class MailList
            public static void main(String args[])
                    LinkedList m1 = new LinkedList();
                    m1.add(new Address("J.W.West", "11 Oak Ave",
                           "Urbana", "IL", "118011"));
                    m1.add(new Address("H.S.sandy", "1 k ve",
                           "Bana", "L", "18011"));
                    m1.add(new Address("K.Satish", "1 104 Clarence Street",
                            "Strathfield", "NSW", "135"));
                    Collections.sort(m1);
                    Iterator itr = m1.iterator();
                    while(itr.hasNext())
                            Object element = itr.next();
                            System.out.println(element + "\n");
    }

    look at the API for FileWriter.
    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • Manual Exporting of BLOB specific table to text file

    Hi,
    Our application is having 60000 record in a BLOB specific table.
    My requirement is to export the entire table data to text files .
    When I tried converting BLOB to sting and writing to file, it took almost 3 mins for 100 records, if so, will take so much of time in exporting data from BLOB specific table.
    I am using the following logic,
    byte[] bdata = blob.getBytes(1, (int)blob.length());
    String data1 = new String(bdata);
    buffer.append(data1);
    Can anyone please tell me how can I speed up the operation.

    >
    Our application is having 60000 record in a BLOB specific table.
    My requirement is to export the entire table data to text files .
    >
    Welcome to the forum!
    If you are looking for a pure Java solution you should post this question in the JDBC forum.
    https://forums.oracle.com/forums/category.jspa?categoryID=288
    Unless your BLOB data is located inline you are going to use Oracle to read 60,000 files, one at a time, and then use Java to write 60,000 files one at a time.
    That will be a very slow process.
    Also - your Java code is only going to read the LOB locator and inline BLOB data since you are not getting and processing the actual stream.
    See 'Reading and Writing BLOB, CLOB and NCLOB Data' in the JDBC Dev Guide for details
    http://docs.oracle.com/cd/B28359_01/java.111/b31224/oralob.htm#sthref756

  • How to find the ocuurence of a word from LIST A in LIST B in a text file?

    Hey if you look at the text file there is LIST A and LIST B.. i need to find the ocuurence of a word from LIST A in LIST B. Eg: if my output is (1,3)
    then first word from LIST A occurs in 3 places in LIST B.
    Can you please get the sample code to do this process.
    Please let me know..
    My text file looks like this below :
    phrases.txt
    LIST A
    aamsz
    abaffiliate
    aboard casino
    above computer
    above pop
    above violat
    LIST B
    http://209.153.231.131
    HTTP/1.0 200 OK
    Server: Microsoft-IIS/5.0
    Date: Mon, 02 Feb 2004 11:53:26 GMT
    IISExport: This web site was exported using IIS Export v2.2
    IISExport: This web site was exported using IIS Export v2.2
    Content-Length: 274
    Content-Type: text/html
    Set-Cookie: ASPSESSIONIDSSDBBBAR=OOGFKOJBMKMDCGPIHPADALHB; path=/
    aboard casino
    Cache-control: private
    abaffiliate
    above computer

    The key difference is that Vector is synchronized whilst ArrayList is not. Synchronized means that the classes methods can safely be accessed by different threads and as your application will not be multithreaded then the ArrayList is possibly the better option.
    To store Strings in an ArrayList, you first need to declare the ArrayList object something like this;
    ArrayList<String> listAList = new ArrayList<String>();and you would obviously do something similar for the ArrayList that will hold the Strings that should belong to List B.
    The first thing to note is that you can use the new (well new in version 1.5 anyway) generics techniques to specify the type of the object the ArrayList will hold; Strings in this case.
    To add a value into the ArrayList once you have read it from the file and decided if it belongs in the List A or List B ArrayList, all you need to do is call the add() method of the ArrayList something like this;
    // Assume that you read the line from the file into a variable called temp;
    listAList.add(temp);To compare the two lists, the easiest option would be to iterate through one ArrayList and ceheck to see if the values you recover from it are duplicated in the other ArrayList. Luckilly, ArrayList has another method that helps here, it is called contains();
    Assuming that you have two ArrayList(s), one called listAList that holds the Strings that belong to List A and another called listBList that holds the Strings that belong to ListB, you could do something like this to check for duplicates;
    for(String element : listAList) {
        if(listBList.contains(element)) {
            System.out.println("Found a match");
    }Hope that helps.

  • Download internal table as text file with comma separation

    hi all
    I wanted text file separated by comma. I used the CSV function module, but the result is separeted by semicolon,instead i need comma.
    Kindly suggest some solution.
    Thanks
    Subha

    use this fm to convert to csv file
    CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
        EXPORTING
          I_FIELD_SEPERATOR    = ','
        TABLES
          I_TAB_SAP_DATA       = ITAB_FINAL
        CHANGING
          I_TAB_CONVERTED_DATA = ITAB_OUTPUT
        EXCEPTIONS
          CONVERSION_FAILED    = 1
          OTHERS               = 2.
      IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    itab_output is of type ITAB_OUTPUT TYPE TRUXS_T_TEXT_DATA,
    and then download using gui_download
    CALL FUNCTION 'GUI_DOWNLOAD'
          EXPORTING
            FILENAME                = W_FILENAME
            FILETYPE                = 'ASC'
          TABLES
            DATA_TAB                = ITAB_OUTPUT
          EXCEPTIONS
            FILE_WRITE_ERROR        = 1
            NO_BATCH                = 2
            GUI_REFUSE_FILETRANSFER = 3
            INVALID_TYPE            = 4
            NO_AUTHORITY            = 5
            UNKNOWN_ERROR           = 6
            HEADER_NOT_ALLOWED      = 7
            SEPARATOR_NOT_ALLOWED   = 8
            FILESIZE_NOT_ALLOWED    = 9
            HEADER_TOO_LONG         = 10
            DP_ERROR_CREATE         = 11
            DP_ERROR_SEND           = 12
            DP_ERROR_WRITE          = 13
            UNKNOWN_DP_ERROR        = 14
            ACCESS_DENIED           = 15
            DP_OUT_OF_MEMORY        = 16
            DISK_FULL               = 17
            DP_TIMEOUT              = 18
            FILE_NOT_FOUND          = 19
            DATAPROVIDER_EXCEPTION  = 20
            CONTROL_FLUSH_ERROR     = 21
            OTHERS                  = 22.

  • Uploading into database table from text file using tab (GUI_UPLOAD)

    i have small doubt
    i have 3 fiels in text file using tab as separator
    i need to update into database table 'ZABPSP_01'
    from 's.txt' located in local disk.
    My code is below.
    Please let me know the correction.
    Awaiting for ur response.
    Thanks in advance
    REPORT  ZABPSPPRG_02.
    TABLES: LFA1,MARA,KNA1,ZABPSP_01.
    DATA:  begin of itab occurs 0,
    IKUNNR type zabpsp_01-kunnr,
    IMATNR type zabpsp_01-matnr,
    IADRNR type zabpsp_01-adrnr.
    DATA:END OF ITAB.
    DATA: FILENAME1 TYPE STRING.
    FILENAME1 = 'C:/s.txt'.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = FILENAME1
      FILETYPE                      = 'ASC'
       HAS_FIELD_SEPARATOR           = 'X'
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
      DAT_MODE                      = ' '
      CODEPAGE                      = ' '
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
      CHECK_BOM                     = ' '
      VIRUS_SCAN_PROFILE            =
      NO_AUTH_CHECK                 = ' '
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      TABLES
        DATA_TAB                     = itab.
    EXCEPTIONS
      FILE_OPEN_ERROR               = 1
      FILE_READ_ERROR               = 2
      NO_BATCH                      = 3
      GUI_REFUSE_FILETRANSFER       = 4
      INVALID_TYPE                  = 5
      NO_AUTHORITY                  = 6
      UNKNOWN_ERROR                 = 7
      BAD_DATA_FORMAT               = 8
      HEADER_NOT_ALLOWED            = 9
      SEPARATOR_NOT_ALLOWED         = 10
      HEADER_TOO_LONG               = 11
      UNKNOWN_DP_ERROR              = 12
      ACCESS_DENIED                 = 13
      DP_OUT_OF_MEMORY              = 14
      DISK_FULL                     = 15
      DP_TIMEOUT                    = 16
      OTHERS                        = 17
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    IF sy-subrc EQ 0.
    zabpsp_01-kunnr = ITAB-IKUNNR.
    zabpsp_01-matnr = ITAB-IMATNR.
    zabpsp_01-adrnr = ITAB-IADRNR.
    WRITE : / ' UPLOAD SUCCESS ' .
    ENDIF.
    \[subject changed, don't write everything in upper case!\]
    Edited by: Jan Stallkamp on Aug 6, 2008 2:39 PM

    Hi,
    After upload modify the code like below. Also change the file name as some one suggested already. If u are still facing problems then check in debug mode what is happening after FM call.
    CALL GUI_UPLOAD FM.
    IF sy-subrc EQ 0
    IF NOT itab[] IS INITIAL.
    MODIFY ZABPSP_01 FROM TABLE itab.
    WRITE : / ' UPLOAD SUCCESS ' .
    ELSE.
    WRITE 'No data in file'.
    ENDIF.
    ELSE.
    WRITE 'Upload failure'.
    ENDIF.
    Thanks,
    Vinod.

  • Cannot Export Music Library to a Text file

    Hi,
    I just updated to Version 12. In the previous version you were able to export your itunes music listing to a text file. The feature has disappeared is there a workaround?

    Enable menu bar with Ctrl+B if needed.
    Select the Music view.
    File > Library > Export Playlist.
    tt2

  • Loading data from oracle table to text file........

    how can i load data from a oracle table to a text file or CSV file using PL/SQL procedures where the pls/sql code will take the table name dynamically.........
    soumen

    Try this thread..
    Is it possible to export a pl/sql region as a csv file?

  • Fastest way to export to a pipe-delimited text file

    I'm using Oracle 9i and need to export a table that has 150 million rows into a text file (or multiple text files based on a query that divides the table). I'd like it to be pipe-delimited and without quotes around strings.
    How can this be done so that it runs fast? Keep in mind, I'm kind of a newbie.

    I don't know what the fastest method would be but I would put quite a bit of money on it not being the Oracle SQL Developer tool, which is the subject of this forum.

  • How to export data in to a Text File

    Hi,
    Can anyone provide any guidance of exporting data in an Advanced Table or data of a VO in to a Text File instead of CSV file.
    Thanks

    Exporting 5 mil records is going to require lot of memory and even if you implement, the users are not going to like it.
    May be, you can implement a 'submit' button and when the user clicks submit a concurrent program. This concurrent program will generate the output file.
    You can do other fancy things like displaying the status and to download the file in OAF itself.
    HTH
    Srini

  • How to write list values to a text file?

    Hi. Does anyone know how to write values stored in a List to a text file? I have a program that asks the user to enter a name and stores it in a list. The number of names in the list depends on how many times the user wants to enter a name. The problem is that my writeToFile method, which handles writing values to a text file, only writes one name and overwrites any previous names. How could I fix this so that it goes thru the list and writes every value to the file? Any hints would be appreciated!
    peace
    Chris
    import java.util.*;
    import java.io.*;
    public class StoreNames
    String name;
    char answer;
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    public void anotherName(List a)throws IOException
    System.out.println("Enter another name? (Y or N)");
    answer = (char)System.in.read();
    System.in.skip(2);
    while(answer == 'Y' || answer == 'y')
    inputName(a);
    System.out.println("Enter another name? (Y or N)");
    answer = (char)System.in.read();
    System.in.skip(2);
    if (answer == 'N' || answer == 'n')
    System.out.println("Ok. GoodBye");
    writeToFile(a);
    //prompts user to input names
    public void inputName(List a) throws IOException
    System.out.print("Enter a name: ");
    name = input.readLine();
    a.add(name);
    public void writeToFile(List a)throws IOException
    PrintWriter output = new PrintWriter(new FileWriter("names.txt"));
    output.print(name); //Problem area - handles only one line of input, overwrites previous input
    output.close();

    System.out is an instance of PrintStream (check the API documents for the System class to see this).
    So the easiest way to convert from a "print to screen" class to a "print to file" class is to acquire a PrintStream that prints to a file, and use it exactly the same as you'd have used System.out...
    So start with your console code...
            PrintStream out = System.out;
            for(int i = 0; i <10; i++){
                out.println("Number " +i);
            }Then you adapt to file code:
            FileOutputStream fos = new FileOutputStream("temp.txt");
            PrintStream out = new PrintStream(fos);
            for(int i = 0; i <10; i++){
                out.println("Number " +i);
            out.flush();
            out.close();Note that we flush the stream because for reasons of efficiency files aren't necessarily written to disk until you explicitly ask the system to do so (memory is fast, disks are slow, that's why).
    Closing the stream releases system resources associated with it.
    Actually, that's redundant, because close calls flush automatically, but I left it in for clarity.
    Any use ?

  • What is the best method for writing Multicolum​n List data to a text file?

    I am trying to find the best method for writing the data from a multicolumn list to a text file. Say the list has 7 rows and 6 columns of data. I would like the final file to have the data resemble the Multicolumn List as closely as possible with or without column headers. A sample VI showing how to accomplish this would be greatly appreciated. I realize this is pretty basic stuff, but I can get the output to the file, but it comes out with duplicate data and I am on a time crunch hense my request for help.
    Thank You,
    Charlie
    Everything is Free! Until you have to pay for it.

    Hello,
    I think that the answer to your question it's on the example that I've made right now.
    See the attached files....
    Software developer
    www.mcm-electronics.com
    PS: Don't forget to rate a good anwser ; )
    Currently using Labview 2011
    PORTUGAL
    Attachments:
    Multi.vi ‏12 KB
    Multi.PNG ‏6 KB

  • Upload data from Internal table to text file with  '~' separator

    can anyone help me to download data from internal table to flat file with  ''  separator. GUI_DOWNLOAD is not working in my case ....like for ''  separator

    Here it is
    REPORT  zkb_test1.
    TYPE-POOLS: truxs.
    DATA: i_scarr TYPE TABLE OF scarr,
    i_conv_data TYPE truxs_t_text_data.
    SELECT * FROM scarr INTO TABLE i_scarr.
    CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
      EXPORTING
        i_field_seperator    = '~'
      TABLES
        i_tab_sap_data       = i_scarr
      CHANGING
        i_tab_converted_data = i_conv_data
      EXCEPTIONS
        conversion_failed    = 1
        OTHERS               = 2.
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL METHOD cl_gui_frontend_services=>gui_download
      EXPORTING
        filename                = 'C:\Test1.txt'
        filetype                = 'ASC'
      CHANGING
        data_tab                = i_conv_data
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        not_supported_by_gui    = 22
        error_no_gui            = 23
        OTHERS                  = 24.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    Regards
    Kathirvel

  • Export data from a table to text file using srcipt task

    Hi
    i am new to SSIS
    i have to export data from a table and append it into a existing file through SSIS script task
    please help
    Thanks
    Umesh

    Hi Umesh,
    The data structure of the source table and the structure of the destination file are the same, right? Is the destination file a flat file? Do you have to do it through Script Task? If the destination file is a flat file, this can be done easily by using
    the stock tasks/components other than .NET code. In the Data Flow Task, we choose the appropriate source adapter (such as OLE DB Source or ADO.NET Source) to extract data from the source table, perform transformation if necessary, and then load to the destination
    file via a Flat File Destination. When setting up the Flat File Destination, uncheck the “Overwrite data in the file” option so that the extracted data will be appended to the existing file.
    If you need to implement it through Script Task/Component indeed, you may benefit from the following code examples:
    http://stackoverflow.com/questions/8070163/how-to-add-custom-footer-to-an-ssis-flat-file-seperate-component-or-script-tas 
    http://stackoverflow.com/questions/8467326/add-header-and-footer-row-flat-file-ssis 
    If you need further help about the script, I suggest that you ask a new question in .NET forums where you can get more dedicated support:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=netdevelopment 
    Regards,
    Mike Yin
    TechNet Community Support

  • How to Convert an internal table into Text File

    Hello friends,
    Can you help me to find out the way to convert an internal table data into a flat file.
    the problem is that my internal table contains fields with data type INT also.

    please  go through the code and the parameter passed to the  finction module  ... since  you didn't show your coding  i am giving you the sample code  also ..
    REPORT y_ss_test_ekko .
    * To hold selection data
    DATA: i_ekko TYPE STANDARD TABLE OF ekko.
    * To hold converted text data
    DATA: i_text(4096) TYPE c OCCURS 0.
    * Selection Screen
    PARAMETERS: p_ebeln LIKE ekko-ebeln.
    * Select data into an ITAB based on the selection Criteria
    SELECT * FROM  ekko
             INTO  TABLE i_ekko
             WHERE ebeln = p_ebeln.
    * Process further only if found some data
    IF NOT i_ekko[] IS INITIAL.
    * Convert data in internal table to a delimited text data
      CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
           EXPORTING
                i_field_seperator    = '|'
           TABLES
                i_tab_sap_data       = i_ekko
           CHANGING
                i_tab_converted_data = i_text
           EXCEPTIONS
                conversion_failed    = 1
                OTHERS               = 2.
      IF sy-subrc <> 0.
        WRITE: / 'Program failed to Convert data.'.
      ELSE.
    *   Download convert data to Presentation Server
        CALL FUNCTION 'DOWNLOAD'
             TABLES
                  data_tab = i_text
             EXCEPTIONS
                  OTHERS   = 8.
        IF sy-subrc <> 0.
          WRITE: / 'Program failed to download data.'.
        ENDIF.
      ENDIF.
    ENDIF.
    reward  points  if it is  usefull   ....
    Girish

Maybe you are looking for

  • Using iPad2 to fill PDF forms with calculating cells

    I currently have the PDF Expert app. installed.  I have created a PDF form with calculating cells and cells with multiple selections using Adobe Acrobat X Pro.  It works on my PC on 2 different PDF reader apps, however when I load it in PDF Expert on

  • Loading an external XML attribute to an internal

    str = "<mytag name='Here should have attributes from an external file'>''</ mytag> "; doc = new XML (str); foot_name.text = doc.firstChild.attributes.name; trace (y); help...

  • ORA-07445: [ACCESS_VIOLATION] [_pevm_CMP3N+21] [PC:0x60BA7455] [ADDR:0x6]

    Hello, I have this error on a Oracle database 10.2.0.1 with WIndows 2003 standard edition ORA-07445: [ACCESS_VIOLATION] [_pevm_CMP3N+21] [PC:0x60BA7455] [ADDR:0x6] [UNABLE_TO_READ]. I look into the metalink but the parameter [_pevm_CMP3N+21] does not

  • Combining Multiple Files Into One PDF

    When I try to combine MS Word or PDF files, I receive an unexpected error occurred please try again later message.  How do I combine the files?

  • Poor gigabit performance, how do I improve it?

    Hello, I have a 1st generation 2x2Ghz power mac g5, and I'm trying to build a gigabit network with some PCs and a brand new MacBookPro (what a laptop!). Although the gigabit network is up and running (and either the laptop or the g5's ifconfigs say s