Update parent status based on all children status and sum of children amount.

Hi,
I need to write sql query for the following scenarios.
We have 3 financial systems (sys1, sys2, sys3) where a same transaction gets entered independently into each system OR entered into one and exported to the other system. Transaction need not be in all 3 systems.
We need to create reconcile report to see the status of transaction and display if it is reconciled or not. For this, in our stored procedure we are pulling data from 3 systems into temp tables and using CTE and other logic marking each transaction status
in each system temp table. One of the systems (eg sys1), we made it as source.
Sys1 temp table has both parent and child records and are distinguished using type. Sys2 and sys3 has only children records.  When report is created, we are showing parent  from sys1 temp table and
children from new temp table where children status is updated based on availability of it in all 3 systems.
DECLARE
@sys1 TABLE
ID int,
childID varchar(20),
ParentID varchar(20),
RecType decimal(3,0),
SettleDate smalldatetime,
Principal money,
Sys3ID varchar(16)
NULL,
Sys2ID int
NULL,
                        Status varchar(25) NULL
DECLARE
@sys2 TABLE
TxID int
PRIMARY KEY NOT
NULL,
CommonTransactionID varchar(16),
SettleDate smalldatetime,
Par money,
Sys3ID varchar(16) NULL,
Sys1ChildID,
Sys1ParentID bigint
DECLARE
@sys3 TABLE
Sys3ID varchar(16),
REFERENCE
varchar(16),
VALUE_DATE datetime,
DIRECTION char(1),
AMOUNT money,
RecSource varchar(2)
Insert Into @sys1 (ID, childID, ParentID, RecType, SettleDate, Principal)
Select 172876, 217955, 217954, 100, ‘2015-03-01’, 100.00
Union
Select 172877, 217956, 217955, 50, ‘2015-03-01’, 15.00
Union
Select 172878, 217957, 217955, 50, ‘2015-03-01’, 25.00
union
Select 172879, 217958, 217955, 50, ‘2015-03-01’, 10.00
Union
Select 172880, 217959, 217955, 50, ‘2015-03-01’, 10.00
union
Select 172881, 217960, 217955, 50, ‘2015-03-01’, 40.00
Insert Into @sys2(TxID, Sys1ID, settleDate, Par)
Select 4336620, 217956, ‘2015-03-01’, 15.00
Union
Select 4336621, 217957, ‘2015-03-01’, 25.00
union
Select 4336613, 217958, ‘2015-03-01’, 10.00
Union
Select 4336614, 217959, ‘2015-03-01’, 10.00
union
Select 4336615, 217960, ‘2015-03-01’, 40.00
Insert into @sys3(Sys3ID, Reference, Value_Date, Direction, Amount)
Select 1, ‘5654471 4336620’, ‘2015-03-01’, ‘O’, 15.00
Union
Select 2, ‘5654481 4336621’, ‘2015-03-01’, 'O',25.00
Union
Select 3, ‘5654491 4336613’, ‘2015-03-01’, 'O',10.00
Union
Select 4, ‘5654501 4336614’, ‘2015-03-01’, 'O',10.00
Union
Select 5, ‘5654511 4336615’, ‘2015-03-01’, 'O', 40.00
After going thru lot of other logic, final temp table will have only children with status assigned. The above temp table data is only for 1 scenario.
The following are status of children.
This is how status of children is determined:
Not Settled – All child records start as Not settled in temp tables.
Settled – when record exists in sys3 and other criteria is met.
Partially settled – record exists in sys3 and either in sys1 or sys2 or other criteria is not met.
Reconciled – child record should exist in all 3 systems and all criteria is match
Mismatched – record has wrong amount when compared in any of 2 systems.
**************** My Part below*******************
My part is to update the status of parent based on children status and parent amount must match sum of child amounts. If amounts don’t match, then leave the status of parent as null.
Determining the status of parent:
Not Settled – None of children has yet settled.
Settled – All children are settled.
Partially settled – some of children are as settled OR 1+ children are partially settled.
Reconciled – All children are reconciled.
Partially Reconciled – some children are partially reconciled.
Null – 1 or more childen has a status of mismatched.
AND sum of children amount should match parent amount
How can I update the status of parent based on all children and sum of amount of children equal to parent amount.
Thanks,
Spunny

>> We have 3 financial systems (sys1, sys2, sys3) where the same transaction gets entered independently into each system OR entered into one and exported to the other system. Transaction need not be in all 3 systems. <<
Your design is fundamentally wrong. In RDBMS, we want to have one fact, one way, in one place in the schema. The goal of all databases is to remove redundancy, not increase it. This not just SQL; this was true for hierarchical and network databases before them! 
>> We need to create reconcile report to see the status of transaction and display if it is reconciled or not. For this, in our stored procedure we are pulling data from 3 systems into temp tables and using CTE and other logic marking each transaction
status in each system temp table. One of the systems (eg sys1), we made it as source. <<
You have re-invent the worst of 1970's file processing, but you want to use a temp table instead of scratch tape. This is not RDBMS or good SQL. 
>> Sys1 temp table has both parent [sic] and child [sic] records [sic] and are distinguished using type. Sys2 and sys3 has only children [sic] records [sic]. When report is created, we are showing parent from sys1 temp table and children from new temp
table where children [sic] status is updated based on availability of it in all 3 systems. <, 
The terms “child” and “parent” are not part of RDBMS. They come from network databases. You are building fake pointer chains we do have referenced and referencing tables. Or do you mean to model weak and strong entities? Where is the DRI actions?
These things are not tables! They have no keys, so they are called (garbage) piles. But even the garbage is wrong. There is no generic “id” in RDBMS; it has to be “<something in particular>_id” to be valid. Since you do not do math on it, it should not
be a numeric. 
A “rec_type” is a nominal scale, so it cannot be a numeric either! Likewise, we have no generic “status”, but a status is state of being so it has to have a temporal dimension. And did you know that “reference” is a reserved word in SQL as well as another ISO-11179
violation. 
The MONEY data type does not do correct math. Google it! It is another Sybase left-over that nobody should ever use. 
Finally, you used the old Sybase INSERT INTO ..SELECT..), .. disaster instead of the ANSI/ISO Standard VALUES table constructor. 
>> This is how status of children [sic] is determined: ..
My part is to update the status of parent [sic] based on children [sic] status and parent [sic] amount must match sum of child [sic] amounts.<<
Your narrative describes what Tom Johnston called a Non-Normal Form Redundancy. We do not put summary data in the strong entity; another basic data modeling principle. We build a VIEW that gives us the current summary. Your mindset is still in punch cards and
magnetic tape files. 
"No matter how far you have gone down the wrong road, turn around!" -- Turkish proverb. 
Can you start over and do it right? 
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • I did a software upgrade to IOS6 and my Iphone4S is now unable to update. Do I lose all my contacts and calendar entries when I restore?

    I did a software upgrade to IOS6 and my Iphone4S is now unable to update. Do I lose all my contacts and calendar entries when I restore?

    You should be syncing all your contacts and calendars with your computer, either via iCloud or iTunes, so it is easy to re-sync them back to the phone after you restore.

  • I want to ask company when user update to ios7 it stuck all of device and not clearly about apple id to active how to solve it or just keep all of device into recycle because can not use?

    i want to ask company when user update to ios7 it stuck all of device and not clearly about apple id to active how to solve it or just keep all of device into recycle because can not use?

    You need to enter the Apple ID and password that was used to set up/activate the phone. There is no way around this.

  • Last update to itunes wiped out all downloaded files and playlists....NOT IMPRESSED!! Any ideas??

    Last update to Itunes wiped out all downloaded files and playlists. Not Impressed. Been searching for resolutions...everywhere. No such luck.....tried everything other than looking in the pc's registry.....not sure how to pull that off , but itunes is bugging me with these updates.....HELP!!! Lots of lost money here and no help.

    See Empty/corrupt library after upgrade/crash.
    tt2

  • TS1702 Hi, I can't download any application from the aap store it's on a waiting mode, I tried to update some application that I all ready have and it's the same

    Hi, I can't download any application from the aap store it's on a waiting mode, I tried to update some application that I all ready have and it's the same

    You will not lose everything on you phone if you backup prior to updating. You can do it maunaully (simply by syncing your phone with itunes) but when you update iTunes will prompt you do back up your phone anyways. After you've updated you can reload everything on to your phone with the itunes back up.

  • Why when I updated my apps I lost all my apps and information on my ipad

    why when I updated my apps on my iPad I lost all my apps and information I had and pic.

    Please give some more details about what you were doing when you lost your apps and information so that we can have a better idea of what happened!
    With that said, you can always re-download your apps from the purchased section of the app store on your iPad.

  • I have updated to OSX, have lost all my photos and can't enter iphotos as its updating?

    I have lost all my photos after updating to OS X, from both my Mac and iphone? When i log on to my Mac, it won't allow me to enter iphotos as it say's it's updating this has been happening now for over a week, can i get my photos back?

    Mac OS X: How to quit an unresponsive application using Force Quit

  • After I updated my phone I lost all my pictures and the new apps I downloaded. I would really love my pictures back does anyone know how? It said that the backup failed during the process. Is it all lost?

    I went to update my phone and after the update I recieved a message that it failed and that the back up failed. I had to restore my phone to stock. I just want to know if there was a possibility to get my pictures back. I tried to get my phone to restore from my last back up but it wouldn't do that either. Does anyone have any ideas. I am really only worried about my pictures and videos I had a couple hundred and they were important.

    Thank you. I have been reading about a lot of these occurances and many people have been able to get their pictures back through iexplorer however I am unable to. The error number I got was 50 or something like that. I have a feeling I will not be able to get the pictures back because it said the backup failed after the update failed.

  • Iphone 4 not recognized and will not sync after latest itunes update.  I have done all trouble shooting and uninstalled and reinstalled itunes to no avail.

    iphone 4 not recognized and will not sync after latest itunes update.  I have done recommendedl trouble shooting and uninstalled and reinstalled itunes to no avail. Can I go back to earlier version of itunes or restore computer to fix?

    'The installer has insufficient privileges to modify this file C:\Program Files (x86)\Common Files\Apple\Apple Application Support\Web kit.resources\inspector\Images\Spinner Inactive Selected.gif.'
    That one's consistent with disk/file damage. The first thing I'd try with that is running a disk check (chkdsk) over your C drive.
    XP instructions in the following document: How to perform disk error checking in Windows XP
    Vista instructions in the following document: Check your hard disk for errors
    Windows 7 instructions in the following document: How to use CHKDSK (Check Disk)
    Select both Automatically fix file system errors and Scan for and attempt recovery of bad sectors, or use chkdsk /r (depending on which way you decide to go about doing this). You'll almost certainly have to schedule the chkdsk to run on startup. The scan should take quite a while ... if it quits after a few minutes or seconds, something's interfering with the scan.
    Does the chkdsk find/repair any damage? If so, can you get an install to go through properly afterwards?

  • Update superior equipment status based on sub equipment status

    Dear friends,
    I have a scenario for calibration process for  which there are two equipments .One sub equipment and the other superior equipment. Calibration process is done for sub equipment and I have given usage decision as rejected based on which sub equipment staus gets updated as NPRT(PRT not ready for use). Now the client requirement is as that the superior equipment also get the status NPRT since they are linked through superior/sub equipment relation. Kindly suggest some solutions.
    best regds
    Arun

    Dear friends ,
    I have observed that if a sub equipment is assigned to a superior equipment ,the equipment status of sub equipment does not get updated when calibration process is run.(NPRT status does not get updated if an equipment is installed to a superior eqpt when usage decision is made for not accepted). So there is no possiblity of updating the superior equipment status. Hence kindly ignore my query.
    best regds
    Arun

  • Update activity status based on Customer request status,

    Hello,
    I have a requirement to update the status field of a service request activity to Completed when the service request status = closed. Any suggestions?
    Thanks,
    SKJ

    If the field they are updating is in the same object it shouldn't be an issue. If another object needs to be updated then the workflow won't work.
    Integration events can be used for this. generate a event and have a external process poll the integration event queue for new events. when received, it can do whatever is necessary via web services.

  • Firefox displays "Stopped" in the status bar; stops all the tabs and does not do anything!

    Firefox displays "Stopped" in the status bar after running for a few minutes. It does not do anything on the page unless it is killed by opening the task manager. Sometimes I even have to restart the computer. And if that also doesn't work that shut down using the power button. Others have reported similar issues too.
    == This happened ==
    Every time Firefox opened
    == couple of weeks ago

    See:
    * http://kb.mozillazine.org/Windows_Media_Player#Missing_plugin
    * http://windows.microsoft.com/en-US/windows/downloads/windows-media-player (see Firefox)
    * http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx

  • HT4097 im trying to update my ipad i have all backed up and am ready i start it last about 30 min and tell me that it is timing out on internet

    I've been trying to update my ipad all day, and it keeps stopping with an error that reads, "There was a problem downloading the software for the iPad 'Becki's iPad.'  The network connection timed out." My question is, how can I prevent this from happening again? My ipad is currently running on 4.3.3 software version.

    beckab wrote:
    ...  The network connection timed out." My question is, how can I prevent this from happening again? ...
    If using windows...
    Temporarily disable your firewall and antivirus software and try again...
    See here for Connection Issues
    http://support.apple.com/kb/TS1379
    From Here
    http://www.apple.com/support/itunes/troubleshooting/

  • HT4890 i maid a version update , but when turn on all the data and contcats are old where can be the last dated update

    Dear all
    i have maid a version update to my iphone
    the system has asm me before to make a buck up i did confirm to be on i cloud
    after the new instlation compleitemd on th eiphoen theor was not contcats
    only nimbers wit h no names
    i have tryeid few way and at last i have recived soem list of contacts old date make be a year old
    then i wend to icloud and alos their the list is old
    as wellon th emac it is old
    where is the data and hwo can i get back to what i had on the day of bucking up
    thax
    nati

    There are multiple reasons that lead to issue. You should read the troubleshooting guide to get the right solution to solve the issue: iPhone, iPad, or iPod touch not recognized in iTunes for Windows - Apple Support

  • After firefox updated to version 6.02, all bookmarks, history and settings were missing. It looks like my old profile was overwritten with a new blank one.

    running windows 7 on a Dell desktop. Firefox updated yeaterday to version 6.02. When I next opened it, I could not find anything nor would the software let me restore bookmarks from the backup.

    A possible cause is a problem with the file places.sqlite that stores the bookmarks and the history.
    *http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox
    See also:
    *http://kb.mozillazine.org/Preferences_not_saved
    *https://support.mozilla.com/kb/Preferences+are+not+saved

Maybe you are looking for