Hi all,I am trying to pull the current value of each corresponding column value from a table valled "unsaccountB" to use in the query below. UnsAccountB tbl is linked to DialogWatchOperation tbl via xObjectKey.UnsaccountB can be considered as parent of DialogWatchOperation. Basically I need "newVal " column to be populated with the corresponding value from unsaccountB table. I am hoping that I will get help or guidance..
NewValue is not column it is just a name(alias) but that column must contain the value of outputed column "ColumnName" in the query statement above. Basically using above data my newVal column should be populated as follow:NewVal=dc/test2/ (which is the value of the output column 'CanonicalName' on unsaccountB table)Distnguest Name of John (which is the value of output column 'DistinguishedName' on unsaccountB tbl)
DECLARE @TargetSystem nvarchar(35) = 'finsoft'DECLARE @sDate datetime ='2012-01-01'DECLARE @eDate datetime ='2012-07-31'DECLARE @personelNumber nvarchar(32) = ''DECLARE @firstName nvarchar(32) = ''DECLARE @lastName nvarchar(32) = ''DECLARE @userName nvarchar(32) = ''DECLARE @accountType tinyint = '1' --- 0/1 { 0=SecAcc;1=PrimAcc } -----------> Gets record's latest old column values <-------------------- if @TargetSystem <> 'ADS' SELECT p.firstname,p.lastname,p.PersonnelNumber, u.XProxyContext, dw.[OldValue],newVal ='' ,dwo.operationDate, dwo.OperationType,dbc.ColumnName,dbc.TableName FROM DialogWatchProperty dw INNER JOIN DialogWatchOperation dwo ON dw.UID_DialogWatchOperation = dwo.UID_DialogWatchOperation INNER JOIN UNSAccountB u ON dwo.ObjectKey = u.xObjectKey INNER JOIN Person p ON p.uid_person = u.uid_person INNER JOIN DialogColumn dbc on dbc.UID_DialogColumn = dw.UID_DialogColumn where ---OperationType = 'U' dwo.operationDate between convert(varchar,@sDate,1) and convert(varchar,@eDate,1) And u.ManageLevel = (case when @accountType is not null then @accountType else u.ManageLevel end) And u.XProxyContext = @TargetSystem And p.FirstName = (case when @FirstName <>'' then @FirstName else p.FirstName end) And p.LastName = (case when @LastName <>'' then @LastName else p.LastName end) And p.CentralAccount = (case when @userName <>'' then @userName else p.CentralAccount end) And PersonnelNumber = (case when @personelNumber <>'' then @personelNumber else PersonnelNumber end)Output of above query:firstname lastname PersonnelNumber XProxyContext OldValue newVal operationDate OperationType ColumnName TableNameAbdulkadir Vural 35458 FINSOFT FINSOFT/FINSOFT/ABDULKADIR SOYADI 15458 2012-04-11 12:08:19.167 U CanonicalName UNSAccountBAbdulkadir Vural 35458 FINSOFT ABDULKADIR SOYADI 15458 2012-04-11 12:08:19.167 U cn UNSAccountBAbdulkadir Vural 35458 FINSOFT CN=ABDULKADIR SOYADI 15458,CN=FINSOFT,dc=finsoft 2012-04-11 12:08:19.167 U DistinguishedName UNSAccountBAbdulkadir Vural 35458 FINSOFT ABDULKADIR 2012-04-11 12:08:19.167 U FirstName UNSAccountBAbdulkadir Vural 35458 FINSOFT SOYADI 15458 2012-04-11 12:08:19.167 U LastName UNSAccountBAbdulkadir Vural 35458 FINSOFT 0 2012-04-11 12:08:19.167 U ManageLevel UNSAccountBAbdulkadir Vural 35458 FINSOFT P 2012-04-11 12:08:19.167 U TSTIDM_Consistent UNSAccountBAbdulkadir Vural 35458 FINSOFT 2011-11-29 14:51:50.770 2012-04-11 12:08:19.167 U XDateUpdated UNSAccountBAbdulkadir Vural 35458 FINSOFT sa 2012-04-11 12:08:19.167 U XUserUpdated UNSAccountBUnsAccount B tbl sample data:UID_UNSAccountB XProxyContext UID_UNSContainerB UID_Person cn DistinguishedName ObjectGUID CanonicalName XDateInserted XDateUpdated XUserInserted XUserUpdated XTouched XObjectKey ManageLevel IsGroupAccount FirstName LastName AccountExpires AccountDisabled MatchPatternForMembership AccountName RiskIndex TSTIDM_Consistent TSTIDM_DeactivatedBySystem TSTIDM_AccountBranchMapping TSTIDM_CashBox TSTIDM_DepartmentMapping TSTIDM_EntitledTo TSTIDM_JobMapping TSTIDM_PrimaryBranchMapping TSTIDM_SubJobMapping TSTIDM_UID_MappingKey TSTIDM_WorkBranchMapping000278a0-6f59-4006-ad5d-4fcab4226557 BOSS c2460c3b-e7d4-4ebf-89e6-9b12dec54fa9 fc6a8654-77cb-43a8-a62e-9dd6d6a5d29b Fatih Toros CN=Fatih Toros,CN=BOSS,dc=boss NULL BOSS/BOSS/Fatih Toros 2011-07-04 15:43:47.657 2012-04-02 11:58:48.820 sa sa NULL <Key><T>UNSAccountB</T><P>000278a0-6f59-4006-ad5d-4fcab4226557</P></Key> 1 1 Fatih Toros NULL 0 0 NULL 0 D NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL0015caab-6b8e-423a-8c06-cb28e75ad3f8 FINSOFT 2ae72b6c-8f77-4c30-a139-1b608814b8ba 7098334a-9dae-4d48-af4c-457040be94c2 X SOYADI 23532 CN=X SOYADI 23532,CN=FINSOFT,dc=finsoft NULL FINSOFT/FINSOFT/X SOYADI 23532 2011-09-30 14:56:58.130 2011-11-29 14:55:31.250 sa sa NULL <Key><T>UNSAccountB</T><P>0015caab-6b8e-423a-8c06-cb28e75ad3f8</P></Key> 0 0 X SOYADI 23532 NULL 0 0 23532 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL002ce792-7920-4df0-8db4-e9feb63c0511 CARDIX 932a61a6-c75c-4557-b448-b0a139b00df5 NULL Meltem Karakas CN=Meltem Karakas,CN=CARDIX,dc=cardix NULL CARDIX/CARDIX/Meltem Karakas 2011-06-29 16:59:31.540 2011-06-29 16:59:31.540 sa sa NULL <Key><T>UNSAccountB</T><P>002ce792-7920-4df0-8db4-e9feb63c0511</P></Key> 0 1 Meltem Karakas NULL 0 0 makarakas 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL