Last active
December 23, 2015 19:39
-
-
Save FrankDeGroot/6684148 to your computer and use it in GitHub Desktop.
Compare database table with XML contents. Kept for code that extracts parameters from a query string, adds them to a SqlCommand and copies values from variables with the same name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$cn = new-object Data.SqlClient.SqlConnection 'Server=.;Database=CIA;Trusted_Connection=true' | |
$cn.open() | |
$q = @' | |
select count(*) from journaalposten.unv_conversierekeningschema | |
where grootboeksysteem='QIS' and maatschappij=@m and gb_rekening=@gbr and kostenplaats=@kp and kostendrager=@kd | |
'@ | |
$cm = new-object Data.SqlClient.SqlCommand -a $q, $cn | |
$p = $cm.parameters | |
[regex]::matches($q, '@\w+') | % { $p.addwithvalue($_.value, '') } | out-null | |
[xml]$x=gc *.xml | |
$cs = @() | |
foreach ($e in $x.ledgerEntryList.ledgerEntry) { | |
$m = $e.businessUnitRef.externalIdentifier | |
$yd = if ($e.yearDamage.nil -eq 'true') { '' } else { $e.yearDamage } | |
foreach ($l in $e.ledgerEntryLineList.LedgerEntryLine) { | |
$gbr = $l.amtTypeCode | |
$kd = if ($l.productVersionCoverageExternalCode.nil -eq 'true') { '' } else { $l.productVersionCoverageExternalCode } | |
$kp = if (-not $yd -and $kd) { '0' } else { $yd } | |
$p | % { $_.value = (get-variable $_.parametername.substring(1)).value } | out-null | |
if (-not $cm.executescalar()) { | |
$cs += "$m.$gbr.$kp.$kd" -replace '\.\.$','' | |
} | |
} | |
} | |
$cn.close() | |
$cs | group | select name | sort name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment