The beauty of sql for configuring vision

If you have labor cross charge or global over-head projects implemented in your enterprise where there is a phase for each profit center, you might have run into the pain of keeping all those over-head projects synchronized with the profit centers (organizational units).

While taking a client of mine to multi-company, I noticed that several of their over-head projects created specifically for configuration purposes and time keeping purposes were out of synch and missing profit centers (organizations) that matched to phases on those projects.  Rather than go through a list of phases on the project and compare by hand the list of profit centers then duplicate a phase for each profit center, which can be a laborious and error-ridden task, I wrote a script which does it automatically.  This script is in the form of a stored procedure which compares the organization table to the structure of a given project, and adds the proper phases to it.  

You’ll notice in my version of the script I call some functions for company, dept, and office… this is because the database is in transition from single to multi company, and I needed those scripts to work before the transition as well.

If you would like me to help you adapt this script to your enterprise let me know.

Oh, one more thing… we did a test run of the configuration of the entire database for multicompany from single company yesterday. With the work that I did automating the configuration (including intercompany billing) it took a total of 2 hours to convert a copy of our live database to multicompany.  That’s pretty fast if you’ve ever done a multicompany configuration.  What’s more, it included lots of cleanup of general ledger entries that were missing profit centers (organizations), key conversions for phases that had the wrong profit center (organization) and configuration for IC Billing with detailed subledgers for 40 profit centers (org units).

If you need help going to multicompany, you should get in touch with me.

Here is the script I refer to at the beginning of this entry.  It handles one project at a time:
(use at your own risk of course… it was written for a specific client so won’t work on your database unless you modify it first)

create procedure fmv_pr_admin_overhead_project_segment_check
(@wbs1 varchar(32), @chargetype varchar(1))
/* overhead project missing segments creator */

/*  12/30/09  LS


1. get a segment row that is in the existing project
2. for each organization that does not have a matching segment, insert a segment row (use one insert for this, not a cursor)
3. use values from step 1 for default values in new rows (except org and segment number values)

select * from organization
select * from pr where wbs1 like ‘oh-%’

declare @wbs2 varchar(16)

set @wbs2 = (select top 1 wbs2 from pr where wbs1 = @wbs1 and sublevel = ‘N’)

insert pr

SELECT top 100 percent
 @wbs1 as ‘wbs1’
      ,dbo.fmv_fn_office( + ‘:’ 
  + (case 
    when dbo.fmv_fn_company(’FMV’ and dbo.fmv_fn_dept(’00’ 
     then ’02’ 
    else dbo.fmv_fn_dept( 
   end) as ‘wbs2’
      , as ‘name’
      ,@chargetype as ‘chargetype’
      ,’N’ as ‘sublevel’
      , as ‘org’
      ,’ADMIN’ as ‘createuser’
      ,getdate() as ‘createdate’
      ,null as ‘moduser’
      ,null as ‘moddate’
  from pr, organization og
 left join (select org, ‘present’ as ‘present’ from pr where wbs1 = @wbs1 and sublevel = ‘N’) existingOrgs
 on =
 where existingOrgs.present is null
 and pr.wbs1 = @wbs1
 and pr.wbs2 = @wbs2
 order by dbo.fmv_fn_office( + ‘:’ + dbo.fmv_fn_dept( 


Have a great day!

Comments or questions for Loren?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s