Focal Point
[CLOSED] Insert Record to table in SQL server

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/4191028331

January 27, 2005, 02:38 AM
Ringo
[CLOSED] Insert Record to table in SQL server
I hold the file in the FEX and then I want to insert the hold file content to table in SQL server. How can I do that ?

This message has been edited. Last edited by: Kerry,
January 27, 2005, 01:16 PM
<Pietro De Santis>
Besides any WebFOCUS licencing issues, you can use MODIFY to update the SQL table

Something like:

MODIFY FILE table-name
FIXFORM FROM hold-file-name
MATCH key-field1 key-field2...
ON MATCH UPDATE *
ON NOMATCH INCLUDE
DATA ON hold-file-name
END

Or, you could use SQL pass-through.
January 28, 2005, 02:38 AM
Ringo
But how can I insert data from a HOLD file to the table in SQL server?

Please help !
January 28, 2005, 02:34 PM
TexasStingray
Ringo, If you are licensed to update database with WebFOCUS you can do what was suggested. Here's a more detail example using the famous car file and lets say that car2 is a SQL table that has the same fields and formats that I am printing and holding as HOLDCAR.

TABLE FILE CAR
PRINT DCOST RCOST
BY COUNTRY
BY CAR
BY MODEL
BY BODYTYPE
-*DEFAULT HOLD NAME IS HOLD WHEN AS IS NOT USED
ON TABLE HOLD AS HOLDCAR
END
-RUN
MODIFY FILE CAR2
FIXFORM FROM HOLDCAR
MATCH COUNTRY CAR MODEL BODYTYPE
ON MATCH UPDATE *
ON NOMATCH INCLUDE
DATA ON HOLDCAR
END
January 29, 2005, 12:52 AM
Ringo
Thank you very much !
January 29, 2005, 04:21 PM
GCohen
The absolutely easiest way to put a HOLD file into a relational database is to do it directly.
eg
TABLE FILE CAR
stuff
ON TABLE HOLD FORMAT ORACLE AS tabname
END
or whatever database you have (the keywords are in the doc). Remember that your id is probably going to be the first part of the table name in the rdbms when you look for it.
January 31, 2005, 11:37 AM
j.gross
quote:
GeraldCohen wrote:
[qb] The absolutely easiest way to put a HOLD file into a relational database is to do it directly.
[/qb]
...but note that, at least with earlier releases (4.x) of WF, the column names for the resulting table will be the standard HOLD MFD aliases: E01, E02,....
August 17, 2010, 09:04 AM
Ted Michalski
Ringo, I need to do the same thing. But, I don't see in this code anywhere where it actually writes it to the database? Where do you actually write the contents of the hold file to the database/table?


7.7.02
Windows
EXCEL, PDF, CSV, TEXT
August 17, 2010, 09:37 AM
Francis Mariani
This code creates a HOLD file and then uses MODIFY to update a table based on the data in the HOLD file:

-SET &ECHO=ON;

SET ASNAMES=ON
SET HOLDLIST=PRINTONLY
SET HOLDFORMAT=ALPHA

TABLE FILE CAR
PRINT
COMPUTE DEALER_COST1/D7 = DEALER_COST * 1.001; AS DEALER_COST
BY COUNTRY
BY CAR
BY MODEL
BY BODYTYPE
ON TABLE HOLD AS H001
END
-RUN

MODIFY FILE CAR
FIXFORM FROM H001
MATCH COUNTRY CAR MODEL BODYTYPE
ON MATCH   UPDATE DEALER_COST
ON NOMATCH INCLUDE
DATA ON H001
END
-RUN

This message has been edited. Last edited by: Francis Mariani,


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
August 17, 2010, 10:05 AM
Francis Mariani
This example creates a HOLD file containing SQL UPDATE commands:

-SET &ECHO=ON;

SET ASNAMES=ON
SET HOLDLIST=PRINTONLY
SET HOLDFORMAT=ALPHA

TABLE FILE CAR
PRINT
COMPUTE DEALER_COST1/D7 = DEALER_COST * 1.001; NOPRINT
COMPUTE DEALER_COST2/A10 = FTOA(DEALER_COST1, '(D7c)', 'A10'); NOPRINT

COMPUTE SQLUPDATE/A200 = 'UPDATE CAR ' |
  'SET DEALER_COST = '  | DEALER_COST2 |
  ' WHERE COUNTRY = ''' | COUNTRY      || '''' |
  ' AND CAR = '''       | CAR          || '''' |
  ' AND MODEL = '''     | MODEL        || '''' |
  ' AND BODYTYPE = '''  | BODYTYPE     || ''';';

BY COUNTRY  NOPRINT
BY CAR      NOPRINT
BY MODEL    NOPRINT
BY BODYTYPE NOPRINT
ON TABLE HOLD AS H001
END
-RUN

SQL
-INCLUDE H001
END
-RUN



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
August 17, 2010, 01:32 PM
Ted Michalski
Thanks for all the suggestions, but I still can't get it to work. Here's what I need to do:

I have the following SQL Server tables:
tableA
tableB

Both tables have different keys.

What I want to do is get the result of column1 + column2 in table A and store it in column4 of tableB.

tableB has 3 key fields: column1, column2 and column3

How should this be coded?


7.7.02
Windows
EXCEL, PDF, CSV, TEXT
August 17, 2010, 01:42 PM
Francis Mariani
Ted,

Don't you feel we've provided enough information to enable you to try different methods. You're now asking us to solve your particular business problem.

"Both tables have different keys" - you haven't told us what the keys are in BOTH tables, just one.

This might get you closer:

-SET &ECHO=ON;

SET ASNAMES=ON
SET HOLDLIST=PRINTONLY
SET HOLDFORMAT=ALPHA

TABLE FILE TABLE1
PRINT
COMPUTE COLUMN4/D15 = TABLE1.COLUMN1 + TABLE1.COLUMN2;
BY TABLE1.COLUMN??? AS COLUMN1
BY TABLE1.COLUMN??? AS COLUMN2
BY TABLE1.COLUMN??? AS COLUMN3
ON TABLE HOLD AS H001
END
-RUN

MODIFY FILE TABLE2
FIXFORM FROM H001
MATCH COLUMN1 COLUMN2 COLUMN3
ON MATCH   UPDATE COLUMN4
ON NOMATCH INCLUDE
DATA ON H001
END
-RUN



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
August 18, 2010, 03:47 AM
Tony A
Something along the lines of -
SQL SQLDBC
  update [your target teradata table] T1
     set column4 = (select column1 | column2
	             from [your source teradata table] S1
                     where T1.column1 | T1.column2 | T1.column3
                         = S1.column1)
;
END
Not entirely WebFOCUS but, providing you get your SQL correct, then it should work.

One advantage of using SQL passthru with SQLDBC is that it doesn't need a .mas or .acx.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10