0

I am trying to export the data from a Firebird store procedure using a loop. I am using Flamerobin tool to do this. I get the results but the columns and rows are all messed up when I export them to csv file! All headers will be in one cell and values are all over the place! Is there any way to export the result to excel or csv file?

 set term!!;
EXECUTE BLOCK RETURNS (
    SOD_AUTO_KEY Integer,
    CURRENCY_CODE Char(3),
    SO_CATEGORY_CODE Char(10),
    SO_NUMBER Char(12),
    INVC_NUMBER Char(12),
    ENTRY_DATE Timestamp,
    SHIP_DATE Timestamp,
    NEXT_SHIP_DATE Timestamp,
    CONDITION_CODE Varchar(10),
    QTY_ORDERED Double precision,
    QTY_PENDING_INVOICE Double precision,
    QTY_INVOICED Double precision,
    UNIT_PRICE Double precision,
    EXCHANGE_RATE Double precision,
    UNIT_COST Double precision,
    ITEM_NUMBER Integer,
    CONSIGNMENT_CODE Char(10),
    NOTES Blob sub_type 1,
    STOCK_LINE Integer,
    STM_AUTO_KEY Integer,
    SERIAL_NUMBER Varchar(40),
    REMARKS Varchar(50),
    PN Varchar(40),
    PNM_AUTO_KEY Integer,
    GR_CODE Varchar(10),
    CUSTOMER_PRICE Double precision,
    OPEN_FLAG Char(1),
    ROUTE_CODE Char(1),
    ROUTE_DESC Varchar(20),
    COMPANY_CODE Varchar(10),
    SITE_CODE Varchar(10),
    COMPANY_NAME Varchar(50),
    COMPANY_REF_NUMBER Varchar(30),
    CUST_REF Varchar(15),
    HOT_PART Char(1) 
    )
     AS
declare i integer;
BEGIN
i=0;
while ( i <= 2 ) do 
BEGIN
   for SELECT SOD_AUTO_KEY,CURRENCY_CODE,SO_CATEGORY_CODE, SO_NUMBER,INVC_NUMBER,ENTRY_DATE, SHIP_DATE, NEXT_SHIP_DATE, CONDITION_CODE, QTY_ORDERED,QTY_PENDING_INVOICE, QTY_INVOICED, UNIT_PRICE, EXCHANGE_RATE, UNIT_COST,ITEM_NUMBER, CONSIGNMENT_CODE, NOTES, STOCK_LINE, STM_AUTO_KEY, SERIAL_NUMBER,REMARKS, PN, PNM_AUTO_KEY, GR_CODE, CUSTOMER_PRICE, OPEN_FLAG, ROUTE_CODE,ROUTE_DESC, COMPANY_CODE, SITE_CODE, COMPANY_NAME, COMPANY_REF_NUMBER, CUST_REF, HOT_PART
   FROM SPB_SALESHISTORY (i)
   into :SOD_AUTO_KEY, :CURRENCY_CODE, :SO_CATEGORY_CODE, :SO_NUMBER, :INVC_NUMBER,
   :ENTRY_DATE, :SHIP_DATE, :NEXT_SHIP_DATE, :CONDITION_CODE, :QTY_ORDERED,:QTY_PENDING_INVOICE,
   :QTY_INVOICED, :UNIT_PRICE, :EXCHANGE_RATE, :UNIT_COST,     :ITEM_NUMBER, :CONSIGNMENT_CODE, :NOTES, :STOCK_LINE,
   :STM_AUTO_KEY, :SERIAL_NUMBER,     :REMARKS, :PN, :PNM_AUTO_KEY, :GR_CODE, :CUSTOMER_PRICE, :OPEN_FLAG, :ROUTE_CODE,:ROUTE_DESC,
   :COMPANY_CODE, :SITE_CODE, :COMPANY_NAME, :COMPANY_REF_NUMBER, :CUST_REF,:HOT_PART
   DO
    suspend;
   i = i + 1;
    end
END!!
SET TERM;!!
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
user3314399
  • 317
  • 4
  • 9
  • 23
  • 1
    I voted as off topic as this question seems to be about a database query tool and its export functionality, not about programming – Mark Rotteveel Jun 06 '14 at 07:24
  • Also when asking such a question somewhere where it is on topic, at least include the options you used to export to CSV and a sample (two or three lines) of the exported data and describe the problem in more detail (or show a screenshot of what happens with the sample lines). – Mark Rotteveel Jun 06 '14 at 07:26
  • As far as I know flameRobin query/proc generated results gets shown in an HTML table, you should save the html and maybe create a small Delphi app to parse the HTML - store it in s TStringGrid, you an then properly export the TStringGrid data to .CSV – Ryno Coetzee Jun 06 '14 at 09:08
  • 1
    Flamerobin is a very Lite RDBMS tool for firebird - I suggest you use IBEXPERT (http://www.ibexpert.net) - It has a personal(free) edition that works beautifully – Ryno Coetzee Jun 06 '14 at 09:10
  • @RynoCoetzee Flamerobin has an 'export to CSV' option. – Mark Rotteveel Jun 06 '14 at 10:33
  • Hi @MarkRotteveel - Yes it does, but in this users case it's simply not doing what is required. Admittedly my first comment was not properly thought out - But I'll stick with my second one. – Ryno Coetzee Jun 06 '14 at 10:43
  • Ryno's response did it! – user3314399 Jun 10 '14 at 16:09

2 Answers2

1

I ended up using IBEXPERT according to Ryno's response.

user3314399
  • 317
  • 4
  • 9
  • 23
0

I often use 2 SQL comands into FlameRobin SQL editor:

output filename_to_export.txt;
select field1, field2 from tablename;

First you say command what file you whant the result of your query will be stored, second you say the query itself. Do not forget, they are two separated (distinct) commands, note the ; after each one. The order doesn't matter. The output remains opened for append results if you perform more queries.

Hans Zimermann
  • 330
  • 2
  • 11