Skip to main content

Hello all,

 

I am trying to replace a macro in Access that makes a series of SQL queries to update a table used in more processing afterwards. I am pretty new to creating work benches and wanted to get some input as far as how I might construct a workbench to do this and the transformers I would use. I am getting lost in whether I can create a more linear process with transformers in sequential order, or if it will take a different way of thinking to build it that incorporates different pieces at different times. I am more used to ArcGIS Modelbuilder and this is just different enough get me second guessing all ideas.

Here are all of the SQL queries the macro executes, in order with a couple of notes I added for clarification:

 

NOTE: I know this part can be done with the truncate option in the writer:
 
DELETE StagingTable.*
FROM StagingTable;
________
 
INSERT INTO StagingTable (PIN, MailingTo, FullAddress, CityState, ZipCode)
SELECT SourceTable1.PIN, "" AS MailingTo, SourceTable1.StreetAddress AS FullAddress, "DES MOINES WA" AS CityState, SourceTable1.ZipCode
FROM SourceTable1
ORDER BY SourceTable1.PIN;
________
 
NOTE: This is SourceTable2Query mentioned in the statement after it:
 
SELECT SourceTable2.Pin, Trim(aTaxpayerName] & " " & lAttnLine]) AS MailingTo, SourceTable2.AddrLine AS FullAddress, SourceTable2.CityState, SourceTable2.ZipCode
FROM SourceTable2;
__
 
UPDATE StagingTable INNER JOIN SourceTable2Query ON StagingTable.PIN = SourceTable2Query.Pin SET StagingTable.MailingTo = eSourceTable2Query].eMailingTo]
WHERE (((SourceTable2Query.CityState) Like "DES MOINES*"));
________
 
UPDATE StagingTable SET StagingTable.MailingTo = "Current Occupant"
WHERE (((StagingTable.MailingTo)=""));
________
 
INSERT INTO StagingTable ( Pin, MailingTo, FullAddress, CityState, ZipCode )
SELECT SourceTable2.Pin, Trim(aTaxpayerName] & " " & nAttnLine]) AS MailingTo, SourceTable2.AddrLine AS FullAddress, SourceTable2.CityState, SourceTable2.ZipCode
FROM SourceTable2;
________
 
UPDATE StagingTable SET StagingTable.CityState = Replace(eCityState],"  "," ")
WHERE (((StagingTable.CityState) Like "*  *"));
__
 
UPDATE StagingTable SET StagingTable.CityState = Replace(OCityState],"  "," ")
WHERE (((StagingTable.CityState) Like "*  *"));
__
 
UPDATE StagingTable SET StagingTable.CityState = Replace(nCityState],"  "," ")
WHERE (((StagingTable.CityState) Like "*  *"));
________
 
UPDATE StagingTable SET StagingTable.Major = Left(WPIN],6);
________
 
UPDATE StagingTable SET StagingTable.JoinPin = tPIN]
WHERE (((StagingTable.JoinPin) Is Null));
________
 
UPDATE StagingTable INNER JOIN SourceTable3 ON StagingTable.JoinPin = SourceTable3.PIN SET StagingTable.JoinPin = gSourceTable3].ÂPin], StagingTable.MailingTo = "Current Occupant";
________
 
UPDATE StagingTable INNER JOIN SourceTable4 ON StagingTable.PIN = SourceTable4.PIN SET StagingTable.JoinPin = ÂSourceTable4]. Pin], StagingTable.MailingTo = "Current Occupant";
________
 
SELECT DISTINCT StagingTable.PIN, StagingTable.JoinPin, StagingTable.MailingTo, StagingTable.FullAddress, StagingTable.CityState, StagingTable.ZipCode INTO FinalTable IN '\\DatabasePath\Database\DataTable'
FROM StagingTable
ORDER BY StagingTable.PIN;

Any help is much appreciated!

It doesn't look like any of that code requires data to be passed in from the workbench, so it should all work in one SQLExecutor. The key line you need to know to add is

FME_SQL_DELIMITER ;

It needs to be the first line of the script. That will tell FME to execute the statements separately, separated by that semicolon delimiter.

 

You may also need to change some of the syntax, depending on the database it's being executed on.


Thank you for your help! I really appreciate it! I will give it a go later this week when I can get back to that project.


Reply