Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 11 total
Thread Script help needed please..
Tue, Sep 25 2018 8:48 PMPermanent Link

Ian Branch

Avatar

Hi Team,
   I am trying to do an export of specific fields from a table mixed with fixed data.

{sql}
SCRIPT
BEGIN
execute immediate 'export table Parts to "Export.csv" in store "Exports"
(
PartNo,
Description,
"B" as Buy,
''S'' as Sell,
''I'' as Inventory,
11800 as AssetAcct,
41770 as IncomeAcct,
54000 as COSAcct,
'''' as ItemPicture,   /* empty field */
Description,
''X'' as UDOS,
'''' as CL1,      /* empty field */
CostPrice)
where blocked = False';
END
{sql}

   If I put B into double single quotes it doesn't like it.  With B in double quotes it seems to like it but doesn't like
the as after it.

   Is this doable in a script at all?

   If not, what is my alternative please?

Regards & TIA,
Ian
Wed, Sep 26 2018 2:42 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian


Never having tried it before I've just tested and it looks as though you can only export columns not insert a constant as you're trying to do. I can see two solutions:


1. create an intermediate temporary or memory table
2. create some computed columns for your table

unfortunately the WHERE clause isn't allowed either so a temporary or in-memory table is the way to go

Roy Lambert
Wed, Sep 26 2018 4:27 AMPermanent Link

Ian Branch

Avatar

Hi Roy,
   Or, I could geberate it OK in a Query and then simply scan through the Query and fill a filestream.
   This is what I have now done and it works fine abd quickly.  One has to remember that you can'y have commas in the
text fields, causes havoc when read into excel. Smile

Ian
Wed, Sep 26 2018 4:32 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian


>    Or, I could geberate it OK in a Query and then simply scan through the Query and fill a filestream.
>    This is what I have now done and it works fine abd quickly. One has to remember that you can'y have commas in the
>text fields, causes havoc when read into excel. Smile

Yup that'll work, or you could use a view

Roy
Wed, Sep 26 2018 11:10 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Ian,

Can I see the structure of the Parts table please?

--
Fernando Dias
[Team Elevate]
Wed, Sep 26 2018 2:49 PMPermanent Link

Ian Branch

Avatar

Fernando Dias wrote:

> Ian,
>
> Can I see the structure of the Parts table please?

Hi Fernando,
   Sure..

CREATE TABLE "Parts"
(
"BLOCKED" BOOLEAN DEFAULT false NOT NULL,
"PartNo" VARCHAR(20) COLLATE "ANSI",
"Description" VARCHAR(70) COLLATE "ANSI",
"SupplierCode" VARCHAR(2) COLLATE "ANSI",
"SupplierPrice" DECIMAL(19,4) DEFAULT 0.00 NOT NULL,
"UOS" VARCHAR(2) COLLATE "ANSI",
"BIN" VARCHAR(20) COLLATE "ANSI",
"COSTPRICE" DECIMAL(19,4) DEFAULT 0.00 NOT NULL,
"SELLPRICE" DECIMAL(19,4) DEFAULT 0.00 NOT NULL,
"DealerPrice" DECIMAL(19,4) DEFAULT 0.00 NOT NULL,
"WTYQTY" SMALLINT DEFAULT 0 NOT NULL,
"WTYMINQTY" SMALLINT DEFAULT 0 NOT NULL,
"WTYMAXQTY" SMALLINT DEFAULT 0 NOT NULL,
"COYQTY" SMALLINT DEFAULT 0 NOT NULL,
"COYMINQTY" SMALLINT DEFAULT 0 NOT NULL,
"COYMAXQTY" SMALLINT DEFAULT 0 NOT NULL,
"UNLIMITED" BOOLEAN DEFAULT false NOT NULL,
"APPLIES_TO" VARCHAR(50) COLLATE "ANSI",
"AccountNo" INTEGER,
"RESERVED" DECIMAL,
"SUPPLIER1" INTEGER,
"SUPPLIER2" INTEGER,
"SUPPLIER3" INTEGER,
"BusCode" CHAR(1) COLLATE "ANSI" NOT NULL,
"RtnQty" SMALLINT DEFAULT 0 NOT NULL,
CONSTRAINT "PARTNO" UNIQUE ("PartNo", "BusCode")
)
VERSION 1.00
READWRITE
UNENCRYPTED
INDEX PAGE SIZE 4096
BLOB BLOCK SIZE 512
PUBLISH BLOCK SIZE 512
PUBLISH COMPRESSION 0
MAX ROW BUFFER SIZE 32768
MAX INDEX BUFFER SIZE 65536
MAX BLOB BUFFER SIZE 32768
MAX PUBLISH BUFFER SIZE 32768
Wed, Sep 26 2018 3:56 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

You could crate a view and add your constants, do calculations and use a WHERE clause.

Richard
Wed, Sep 26 2018 6:41 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Ian,

As already suggested you can both use a View or a Temporary Table.
In my opinion a temporary table would be better because Views are persistent and temporary tables are not, so they are deleted when the session closes if something goes wrong. Also, Temporary Tables are only visible in the same session that created them and thats a huge advantage in a multi-user environment.

Here is the script:

SCRIPT
BEGIN
  DECLARE N INTEGER;
  
  -- Delete the temporary table if it exists
  EXECUTE IMMEDIATE 'SELECT COUNT(*) INTO ? FROM Information.TemporaryTables WHERE Name = ''tmpParts''' USING N ;
  IF N <> 0 THEN
    EXECUTE IMMEDIATE 'DROP TABLE tmpParts' ;
  END IF;

  -- Create temporary table to export
  EXECUTE IMMEDIATE '
    CREATE TEMPORARY TABLE "tmpParts" AS
      (
       SELECT
         PartNo,
         Description,
         ''B'' AS Buy,
         ''S'' AS Sell,
         ''I'' AS Inventory,
         11800 AS AssetAcct,
         41770 AS IncomeAcct,
         54000 AS COSAcct,
         '''' AS ItemPicture,
         Description,
         ''X'' AS UDOS,
         NULL AS CL1,
         CostPrice
       FROM
         Parts
       WHERE
         Blocked = FALSE
      )
    WITH DATA
  ';

  -- Export data
  EXECUTE IMMEDIATE 'EXPORT TABLE tmpParts TO "Export.csv" IN STORE "Exports" ' ;
  EXECUTE IMMEDIATE 'DROP TABLE tmpParts' ;
END

--
Fernando Dias
[Team Elevate]
Wed, Sep 26 2018 10:15 PMPermanent Link

Ian Branch

Avatar

Hi Fernando,
   That's excellent.  Thank you.
Regards,
Ian
Thu, Sep 27 2018 6:39 PMPermanent Link

Ian Branch

Avatar

Hi All,
   Thank you for your inputs.
   I ended up having to do it via a Query & FileStream.  Turns out MYOB doesn't like .csv file with commas in the
description text/field. Smile Should have realised right up front.

Regards,
Ian
Page 1 of 2Next Page »
Jump to Page:  1 2
Image