Write Query Results into a text file

Hello All,
In SAP B1 Query Generator I'm trying to write the results of a query into a text file (.txt). I've tryed with queryout but it doesn't work.
What I want is something like this:
SELECT * FROM TABLE queryout "C:/textfile.txt"
Any sugestions?
Thanks in advance,
Miguel Barbosa

Hello All,
Since yesterday and due to your help, I've found how to solve my problem.
This post is only to share with you and with the others users of Expert Forums how to Write the results of an SQL Query in SAP Business One to a Text File without making it by exportation.
Requested Text File by customer:
Document type in R/3 If Invoice -- 'Z100' - Position 1 to 4 - 4 characters
Supplier Code -- dbo.Table.CardCode -- Position 5 to 15 - 10 characters
Item Code -- dbo.Table.ItemCode -- Position 11 to 25 - 14 characters
Client Code -- dbo.Table.CardCode -- Position 26 to 36 - 10 characters
Client Name -- dbo.Table.CardName -- Posiiton 37 to 100 - 63 characters
Fixed Blank Field -- ' ' -- Position 101 to 120 - 19 blank spaces
Quantity -- dbo.Table.Quantity -- Position 121 to 140 -- 19 characters
Unit Price -- dbo.Table.PriceBefDi -- Position 141 to 160 -- 19 characters
If Invoice Fixed identifier -- 'Z01' -- Position 161 to 163 -- 3 characters
Fixed Blank Field -- ' ' -- Position 164 to 220 -- 56 characters
Document Date -- dbo.Table.DocDate -- Position 221 to 229 - 8 characters
Delivery Date -- dbo.Table.ActDelDate -- Position 230 to 238 - 8 characters
Sales Order Number - dbo.Table.DocNum -- Position 239 to 260 - 21 characters
Delivery Number - dbo.Table.DocNum -- Position 261 to 282 - 21 characters
Follows the code:
EXEC master..xp_cmdshell'bcp
SELECT DISTINCT
''Z100''
+ ''ZP00002091''
+ IsNull(Convert(nVarChar(44), Cast(T0.DocNum As Numeric(38, 0))), '''')
+ ''PTAP''
+ ''          ''
+ ((LTRIM(RTRIM(T1.U_NumConc)))) + SPACE(10-LEN(LTRIM(RTRIM(T1.U_NumConc)))) + ((LTRIM(RTRIM(T3.BaseRef)))) + SPACE(10-LEN(LTRIM(RTRIM(T3.BaseRef))))
+ ''                    ''
+ ''Z02''
+ CONVERT(varchar(10), T1.ActDelDate, 112)
+ CONVERT(varchar(10), T0.DocDate, 112)
+ ''    ''
+ IsNull(Convert(nVarChar(44), Cast(T1.BaseRef As Numeric(38, 0))), '''')
+ ((LTRIM(RTRIM(T1.ItemCode)))) + SPACE(18-LEN(LTRIM(RTRIM(T1.ItemCode))))
+ ''0'' + REPLACE(SPACE(12-LEN(CONVERT(varchar(12), CAST(T1.Quantity AS NUMERIC (38,3))))),'' '',''0'') + REPLACE(((LTRIM(RTRIM(CONVERT(NUMERIC(38,3),T1.Quantity))))),''.'','''')
+ ''0'' + REPLACE(SPACE(12-LEN(CONVERT(varchar(12), CAST(T1.PriceBefDi AS NUMERIC (38,2))))),'' '', ''0'') + REPLACE(((LTRIM(RTRIM(CONVERT(NUMERIC(38,2),T1.PriceBefDi))))) ,''.'','''')
+ ''ZPHA''
+ ''          ''
+ ''  ''
+ ''                         ''
+ ((LTRIM(RTRIM(T4.CardName)))) + SPACE(69-LEN(LTRIM(RTRIM(T4.CardName))))
+ ''                        ''
+ CONVERT(varchar(10), T0.DocDate, 112)
+ ''               ''
FROM
JFOTST.dbo.OINV T0
INNER JOIN JFOTST.dbo.INV1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN JFOTST.dbo.ODLN T2 ON T2.DocNum=T1.BaseRef
INNER JOIN JFOTST.dbo.DLN1 T3 ON T3.DocEntry=T2.DocEntry
INNER JOIN JFOTST.dbo.OCRD T4 ON T1.U_NumConc=T4.AddId
WHERE T0.CardCode=''C52''
queryout "c:\text1.txt" -c -T -x'
Note that in this code everytime you need to use the symbol ' you have to doble it like ''Fixed Text''.
Be aware that there is one UDF so if you try to make this query run in your SB1 you will have to create a UDF called U_NumConc in the document lines.
Database usage:
JFOTST.dbo.OINV T0
JFOTST.dbo - Database Name.
OINV - Table
T0  - Alias
For any doubts I'll be available to help.
Once again thank you very much for all your help.
Together we are stronger!
Kind Regards,
Miguel Barbosa
Edited by: Miguel Barbosa on Aug 18, 2009 12:09 PM
Edited by: Miguel Barbosa on Aug 18, 2009 12:10 PM

Similar Messages

  • How to output a query results into a text file

    How to output a query results into a text file instead of outputing it to the screen..
    is there a way for us to write a SQL query which specifies to output the query results to a text file.
    Pls let me know how to do it
    Thanking u in advance
    regards
    Muraly

    Muraly,
    If you are using SQL*Plus 8.1.6 or later, you can also spool output to a file in HTML format, eg
    SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON
    SPOOL c:\temp\report.html
    SELECT DEPARTMENT_NAME, CITY
    FROM EMP_DETAILS_VIEW
    WHERE SALARY>12000;
    SPOOL OFF
    SET MARKUP HTML ENTMAP OFF
    In iSQL*Plus 9.0.1 (the browser-based interface to SQL*Plus) onwards, you can also send the HTML output to a new web browser window, or an html file -- much easier than the command line method.
    Alison

  • Query Output Into a Text File

    Hello Experts,
    There is a situation where i need ur help.My query is :
    Can I export the output of more than one queries into a * Single Text File * ?
    Also can it be possible to automate these Queries Output to export into the Text File ??
    I also want this Text File Output to mail the end users by using the Process Chain. So is this possible to create a process chain for sending this Text File to the Users via mail ??
    Thanks In Advance
    Neha

    Hello Neha,
    Though i have been working with APDs since some time. But havent actually been involved in designing one. But you could find many documents for the APD on web. And as far as i know, you will need a program to save file from APD.
    I have a document which explains how you can use APD in  process chain. can forward you the same if you want.
    I am sorry as i wasnt of much help for you, as i havent worked on similar requirement before, but this thing just striked in my mind.
    Regards,
    Anuj

  • How to write the resultset into a text file

    how to write the resultset into a text file

    You can use the java.io.* package to write to files.
    API: http://java.sun.com/j2se/1.5.0/docs/api/java/io/package-summary.html
    Tutorial: http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • How to upload the web query result  to CSV/Text file

    Hi,
    Kindly help me on the following.
    1)       I have info-provider (IP), which has info-objects "company code" and "supplier".
    2)       I built a query by putting company-code with a variable in free-charateristics and supplier-code in row.
    3)       When I run this query, it will ask company-code as input and the result will be filtered using company-code.
    4)       For this query, I created a web-template and assigned data-provider to display the data on the web.
    5)       The user wants to enter input company-code='1000' and write the data in a CSV file in a specific directory. i.e, by clicking the execute button (after entering company code) , the result should go to the CSV or text file. i.e. the application should automatically generate the file with query results.
    Note: The user should not use context menu to EXPORT TO CSV OR EXCEL file.
    Please let me know, if there is any tutorial. Thanks a lot advance help.
    Regards
    Kandasamy

    1. SELECT INTO
    Below method will create table when data is inserted from one table to another table. Its useful when you need exactly same datatype as source table.
    Use AdventureWorks2008R2;
    Go
    ---Insert data using SELECT INTO
    SELECT AddressLine1, City
    INTO BothellAddresses
    FROM Person.Address
    where City = 'Bothell';
    GO
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    2. INSERT INTO SELECT
    Below method will need table to be created prior to inserting data. Its really useful when table is already created and you want insert data from
    another table.
    Use AdventureWorks2008R2;
    Go
    ---Create Table
    CREATE TABLE BothellAddresses (AddressLine1 NVARCHAR(60), City NVARCHAR(30))
    ---Insert into above table using SELECT
    INSERT INTO BothellAddresses(AddressLine1, City)
    SELECT AddressLine1, City
    FROM Person.Address
    where City = 'Bothell';
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    Regards,
    Vishal Patel
    Blog: http://vspatel.co.uk
    Site: http://lehrity.com

  • How can I export the query result into access(*.mdb) file?

    Dear all:
    I want to export the query result displayed in jsp into excel file
    and access file. And I have exported the result into excel format successfully, only one line should be added in the head of Jsp:
    <%@ page contentType="application/vnd.ms-excel; charset=gb2312" %>
    But how can I export it in access(*.mdb) file? I have replaced "excel"
    with "access". But it can't achive my goal.
    What should I do to achieve my goal?
    Thanks!

    The only reason your Excel export works is that Excel knows how to interpret comma separated values as an input file format. Access has no such beast.
    If you absolutely must provide info in an mdb, one solution would be to create an ODBC datasource pointing to an empty mdb, then push data into it using the jdbc:odbc bridge, then make a copy of the file and stream it down to the browser. You may run into some ugly file locking items here - set the ODBC connection so it is not shared, and that might help.
    This one is going to be ugly.
    I suppose another approach would be to write a simple VB applicatin that uses automation to create an MDB, then stream that file down to the browser from your servlet. That would almost certainly be faster than the ODBC approach.
    - K

  • Output query result to a text file in ORACLE

    I Need a procedure for generating output query into text file in Oracle.
    for Example,
    A table called Tab1
    the columns are c1,c2,c3,c4,c5.
    I want to store the data in text file in...
    First row as a column name & then, appear the records in second row onwards...
    c1|c2|c3|c4|c5.
    Please kindly provide the solution for this ASAP.

    In case you are using Oracle 9i or higher you should better create a DIRECTORY rather then setting utl_file_dir,e.g.
    SQL> CREATE DIRECTORY log_dir AS '/appl/gl/log';
    SQL> GRANT READ ON DIRECTORY log_dir TO DBA; http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_file.htm#ARPLS069

  • Show Select query result in the text file.

    Hi all,
    i want to show my select statment records in the text file.
    thanks in advance.
    Mob.

    you cannot do a select in a stored procedure.
    you could do something like
    SQL> set serverout on
    SQL> spool output.txt
    SQL> declare
           x varchar2(40);
         begin
           select * into x from dual;
           dbms_output.put_line(x);
         end;
    X
    SQL> spool offor use the utl_file package (more powerfull, less secure, write on the db-server instead of the sqlplus-client)

  • Exporting query results into a csv file using arabic and hebrew chars

    Hi,
    iv'e encountered a problem, using plsql to export a query into a csv file.. the arabic turns into question mark. Do you have any idea why?

    Usually this indicates a mismatch between client and database character set.
    How do you export this query?
    What is your database version?
    What is your client OS?
    T.

  • How to write a return in a text file.

    Hi, i am trying to write diferent lines into a text file, i write strings ending with \r\n but it doesn't work, how could i write in diferent lines?
    Thanks.

    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("myfile.txt")));
    out.println("This is the first line");
    out.println("This is the second line");
    out.flush();
    out.close();Jesper

  • Oracle query export into the Excel file

    Hi,
    How can i automatically export oracle query result into the excel file in oracle?

    SQL and PL/SQL FAQ
    Re: Excel query to Oracle Database
    http://blog.mclaughlinsoftware.com/microsoft-excel/how-to-query-oracle-from-excel-2007/
    Edited by: swapnil kambli on May 28, 2013 11:07 PM

  • Write big query results into a file  ? ?  ?

    Hi all,
    The problem is: I want to write a simple query results into a file. I have no idea how to do that. Only thing I know is utl_ functions. Please advise GURUS how can I use them for big queries. Any example will be really appreciable.
    Thank you in advance.
    Message was edited by:
    v838

    hi,
    i´ld do it like that:
    filedir     varchar2(30):= '/usr/frajo/';
    filename     varchar2(30):= 'file.txt';
    fhandle     utl_file.file_type;
    cursor x is
    select ... (what ever)
    begin
         fhandle := utl_file.fopen (filedir, filename,'a');
         open x;
         loop
              fetch x into (what ever)
              exit when x%notfound;
              utl_file.put_line (fhandle,'text and you results');
         end loop;
         utl_file.fclose(fhandle);
    end;
    happy xmas. franz

  • Write arrays into a text file in different columns at different times

    Hi,
              I have a problem write data into a text file. I want to write 4 1D arrays into a text file. The problem is that I need to write it at different time and in different column (in other word, not only append the arrays).
    Do you have an idea to solve my problem?
    Thank you

    A file is long a linear string of data (text). In order ro insert columns, you need to rewrite the entire file, because colums are interlaced over the entire lenght of the file.
    So:
    read file into 2D array
    insert columns using array operations
    write resulting 2D array to file again.
    (Only if your colums are guaranteed to be fixed width AND you know the final number of colums, you could write the missing columns as spaces and then overwrite later. Still, it will be painful and inefficient, because column data are not adjacent in the file.)
    LabVIEW Champion . Do more with less code and in less time .

  • ORA-06521: PL/SQL: Error mapping function while writting into a text file

    Hi,
    I'm getting an errror ORA-06521: PL/SQL: Error mapping function while trying to write data into a text file.
    I'm using the following code:
    --To create a new directory
    create or replace directory temp as 'C:/temp';
    declare
                    l_str varchar2(1000);
                    output_file utl_file.file_type;
                    cursor test_write_cur is
                         select EMPNO,ENAME,JOB,SAL,HIREDATE
                           from EMP
                         where DEPTNO=30;
    begin
               output_file := utl_file.fopen('TEMP','TESTFILE.txt','w');
               for test_write_rec IN test_write_cur
               loop          
                l_str :=     test_write_rec.EMPNO||'^'||test_write_rec.ENAME||'^'||test_write_rec.JOB||'^'||
                         test_write_rec.HIREDATE||'^'||test_write_rec.SAL||chr(10);
                utl_file.put_line(output_file,l_str);
                     end loop;                                                                           
               utl_file.fclose(output_file);
    end;Please suggest me if i'm wrong.
    Thanks & Regards,
    Sanket Mishra

    Dear Sanket,
    I think you are need use TO_CHAR() function
      to_char(test_write_rec.EMPNO) ,
      to_char(test_write_rec.HIREDATE,'DD.MM.YYYY')
      to_char(test_write_rec.SAL)

  • Grabbing numbers from an array of type double and outputting them into a text file

    In a program im creating i need to save some coordinates of a micropositioner i have into a text file,
    I have the coordinates saved into an array that has 6 digits of precision (6 places after the decimal point).
    I use the number to string conversion and wire that into the write to text file function in labview.  When i open the file
    the numbers that are only displayed are the ones to the left of the decimal point.  I know the number to decimal string function
    rounds the values so if i were to input 3.111111 it would only output the string "3" instead of "3.111111" . 
    So to get all the digits onto the file without rounding i multiplied the number by 10^6 but the decimal point will be lost at that point.
    Is there anyway i can convert numbers into strings without labview rounding to the nearest whole number also without having to multiply by 10^6 and without having to expect the user to know that the coordinates saved in a file are multiplied by an order of magnitude of a million ? 

    ed oh i guess i just missed that function on the pallete after i saw that the function went from number to hex, octal, etc. i assumed that the rest on that row would be some sort of conversion to a different base number, haha thanks.

Maybe you are looking for