Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] SQL PASS THRU - insert multiple rows to a table
Go
New
Search
Notify
Tools
Reply
  
[CLOSED] SQL PASS THRU - insert multiple rows to a table
 Login/Join
 
Member
posted
Hi,
I have a hold file with multiple rows and I need to insert the rows to a table in database using SQL pass thru via scheduled report every week.

Earlier I tried using just one row with all values in the INSERT statement and it works but how to insert multiple rows from a hold file to a table(similar toe ETL)? Also the table has WF_ID as the primary key.

Please let me know. Thanks in advance.

RK

This message has been edited. Last edited by: FP Mod Chuck,


WebFOCUS 8.1.05
Excel, PDF, Pivot, HTML
Windows
 
Posts: 28 | Registered: August 12, 2009Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Have you considered HOLD FORMAT SQLORA or whatever RDBMS you want to populate? It seems a lot less effort than what you describe.


WebFOCUS 8204, Unix, Windows
 
Posts: 1569 | Location: New York City | Registered: December 30, 2015Reply With QuoteReport This Post
Member
posted Hide Post
HOLD FORMAT to RDBMS creates a new table.
I need to load it to the existing table with new rows based on the report date. Also increment the auto generate the primary key.

Thank you
RK


WebFOCUS 8.1.05
Excel, PDF, Pivot, HTML
Windows
 
Posts: 28 | Registered: August 12, 2009Reply With QuoteReport This Post
Expert
posted Hide Post
Do you need to use SQL pass thru ?

You could use MODIFY (Depending on the content like clobs and blobs)


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

 
Posts: 6047 | Location: Land of the Darug people, Terra Australis Incognita | Registered: October 31, 2006Reply With QuoteReport This Post
Virtuoso
posted Hide Post
If your database supports creating multiple VALUES rows, you can generate the SQL for that.

For example:
INSERT INTO CAR (COUNTRY, CAR)
VALUES
  ('JAPAN', 'MAZDA')
, ('ITALY', 'FIAT')
, ('FRANCE', 'PEUGEOT')
, ('FRANCE', 'CITROEN');


The lines under VALUES is what you would generate the code for.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1638 | Location: Enschede, Netherlands | Registered: August 12, 2010Reply With QuoteReport This Post
Gold member
posted Hide Post
To add to Wep's suggestion
 -DEFAULTH &LOOP_CNTR = 0;
-DEFAULTH &CAR = '';
-DEFAULTH &COUNTRY = '';
-DEFAULTH &MODEL = '';

TABLE FILE CAR
PRINT
CAR
COUNTRY
MODEL 
ON TABLE SAVE AS COL_VALUES
END
-RUN
-SET &LOOP_CNTR = &LINES;
-REPEAT :Fetch_Data &LOOP_CNTR TIMES

-READ COL_VALUES  &CAR.A16 &COUNTRY.A10 &MODEL.A20

-TYPE VALUES ARE &CAR &COUNTRY &MODEL
-*Have your sql statement here
 INSERT INTO CAR (COUNTRY, CAR, MODEL)
 VALUES
('&COUNTRY', '&CAR','&MODEL');

-:Fetch_Data 


WF 8.2.04
Windows/Unix
All Formats
In Focus since 2006
 
Posts: 74 | Location: UK | Registered: September 17, 2018Reply With QuoteReport This Post
Guru
posted Hide Post
How many rows do you want to insert? Looping with insert statements is limited, MODIFY is the best way to properly insert data in existing tables.


Test: WF 8.2
Prod: WF 8.2
DB: Progress, REST, IBM UniVerse/UniData, SQLServer, MySQL, PostgreSQL, Oracle, Greenplum, Athena.
 
Posts: 379 | Location: Europe | Registered: February 05, 2007Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Actually, that looks like a great task for my new favourite WebFOCUS function: PUTDDREC

-SET &LIST = 'INSLIST';
FILEDEF &LIST DISK INSLIST.ftm

TABLE FILE CAR
PRINT
  COMPUTE COMMA/A1 = IF LAST COUNTRY EQ '' THEN ' ' ELSE ','; NOPRINT
  COMPUTE INSTUPLE/A256 = COMMA | '(''' || COUNTRY || ''', ''' || CAR || ''', ''' || MODEL || ''')'; NOPRINT
  COMPUTE RESULT/I1 = PUTDDREC('&LIST', &LIST.LENGTH, INSTUPLE, ARGLEN(256, INSTUPLE, 'I3'), RESULT); NOPRINT

-* Other useful stuff you may want to hold unrelated to the insert list

BY COUNTRY NOPRINT
BY CAR NOPRINT
BY MODEL NOPRINT
ON TABLE HOLD
END
-RUN

SQL SQLMSS PREPARE SQLOUT FOR
INSERT INTO CAR (COUNTRY, CAR, MODEL)
VALUES
-INCLUDE INSLIST.ftm
;
END


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1638 | Location: Enschede, Netherlands | Registered: August 12, 2010Reply With QuoteReport This Post
Gold member
posted Hide Post
quote:
PUTDDREC

Good One


WF 8.2.04
Windows/Unix
All Formats
In Focus since 2006
 
Posts: 74 | Location: UK | Registered: September 17, 2018Reply With QuoteReport This Post
Member
posted Hide Post
quote:
Originally posted by Frans:
How many rows do you want to insert? Looping with insert statements is limited, MODIFY is the best way to properly insert data in existing tables.


Every week 200 to 300 rows.


WebFOCUS 8.1.05
Excel, PDF, Pivot, HTML
Windows
 
Posts: 28 | Registered: August 12, 2009Reply With QuoteReport This Post
Member
posted Hide Post
This helps, I will try and update you.:FETCH_DATA is the webfocus command? What does it do?

Thank you

quote:
Originally posted by Addy:
To add to Wep's suggestion
 -DEFAULTH &LOOP_CNTR = 0;
-DEFAULTH &CAR = '';
-DEFAULTH &COUNTRY = '';
-DEFAULTH &MODEL = '';

TABLE FILE CAR
PRINT
CAR
COUNTRY
MODEL 
ON TABLE SAVE AS COL_VALUES
END
-RUN
-SET &LOOP_CNTR = &LINES;
-REPEAT :Fetch_Data &LOOP_CNTR TIMES

-READ COL_VALUES  &CAR.A16 &COUNTRY.A10 &MODEL.A20

-TYPE VALUES ARE &CAR &COUNTRY &MODEL
-*Have your sql statement here
 INSERT INTO CAR (COUNTRY, CAR, MODEL)
 VALUES
('&COUNTRY', '&CAR','&MODEL');

-:Fetch_Data 


WebFOCUS 8.1.05
Excel, PDF, Pivot, HTML
Windows
 
Posts: 28 | Registered: August 12, 2009Reply With QuoteReport This Post
Gold member
posted Hide Post
Hi Riya,
:Fetch_data is a label that I created so that I can loop throught a segment.

You can call it whatever you want. I generally create my labels starting with : but it is not a compulsion.

have a look at following documentation

Looping in WF
Branching


WF 8.2.04
Windows/Unix
All Formats
In Focus since 2006
 
Posts: 74 | Location: UK | Registered: September 17, 2018Reply With QuoteReport This Post
Master
posted Hide Post
Depending on the volume I use SQL Insert, the SQL Loader, and MODIFY. For just a few hundred records, I'd use MODIFY and if all you are doing is inserting then make sure to use "SET SQL LOADONLY" right after the MODIFY statement. This tell MODIFY that all you are doing is loading and it cuts the I/O in half. Without it, MODIFY doesn't know if you are loading, updating or both. As a result, MODIFY will do an unnecessary SQL SELECT first to see if the row exist then do the SQL INSERT when it doesn't. You can see this if you turn traces on.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
 
Posts: 904 | Location: Oklahoma City | Registered: October 27, 2006Reply With QuoteReport This Post
Guru
posted Hide Post
Riya, Using BabakNYC's idea.

Do your
 
HOLD FORMAT SQLORA
 


into a temp table (say TEMP_DATA)

Then run an insert into your table using the temp table.

Insert into MY_TABLE (col1,col2)
Select a.col1 AS col1, 
a.col2 AS col2
FROM TEMP_DATA


Fernando


Prod WF 8.1.04, QA WF 8.2.03, Dev WF 8.2.03
 
Posts: 261 | Registered: October 10, 2006Reply With QuoteReport This Post
Expert
posted Hide Post
Fernando, thats a great idea.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

 
Posts: 6047 | Location: Land of the Darug people, Terra Australis Incognita | Registered: October 31, 2006Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] SQL PASS THRU - insert multiple rows to a table

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.