Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Checking other 5 other columns for change and if they have set field null Expand / Collapse
Author
Message
Posted Thursday, April 3, 2014 1:12 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, August 18, 2014 2:46 AM
Points: 67, Visits: 554
Hi ,

Columns in source
Address1
Address2
Address3
Address4
Address5


Columns in destination
Address_1
Address_2
Address_3
Address_4
Address_5
City

I'm using a conditional split to checking if the data has changed between the source file and the destination table for scd2 history.
But I also need to check if any of the address columns 1-5 have changed for the city column and if they have set the city field to null, I'm hoping to avoid script compent since I don't know c#, is this possible with a derived column?

Thanks for the help.
Post #1557846
Posted Thursday, April 3, 2014 1:45 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:29 AM
Points: 13,570, Visits: 10,448
Can you write some pseudo code that illustrates what you are trying to accomplish?



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1557855
Posted Thursday, April 3, 2014 5:48 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, August 18, 2014 2:46 AM
Points: 67, Visits: 554
Sample SQL script below
Before checks -
Columns from Source
Address1 = 67 office
Address2 = NULL
Address3 = Reading road
Address4 = NULL
Address5 = NULL


Columns from destination
Address_1 = 67 office
Address_2 = NULL
Address_3 = Reading road
Address_4 = NULL
Address_5 = NULL
City_d = London

I used conditional split in SSIS to check for changes between the source and destination column for any checks between columns using the expression below in the conditional split –

((IsNull([Address1]) ? "∆^$@" : [Address1]) != (IsNull([Address_1]) ? "∆^$@" : [Address_1]))|| ((IsNull([Address2]) ? "∆^$@" : [Address2]) != (IsNull([Address_2]) ? "∆^$@" : [Address_2]))||
((IsNull([Address3]) ? "∆^$@" : [Address3]) != (IsNull([Address_3]) ? "∆^$@" : [Address_3]))||
((IsNull([Address4]) ? "∆^$@" : [Address4]) != (IsNull([Address_4]) ? "∆^$@" : [Address_4]))||
((IsNull([Address5]) ? "∆^$@" : [Address5]) != (IsNull([Address_5]) ? "∆^$@" : [Address_5]))

Which compares if any column values have changes since the last load –

If after using the conditional spilt and any of the address columns 1-5 have changed then the City column should be NULL.

For example-

After checks -
Columns from Source
Address1 = 68 office
Address2 = NULL
Address3 = Reading road
Address4 = NULL
Address5 = NULL

Columns from destination
Address_1 = 67 office
Address_2 = NULL
Address_3 = Reading road
Address_4 = NULL
Address_5 = NULL
City_d = London

When copied into the destination table the result would look like below –

Address_1 = 68 office
Address_2 = NULL
Address_3 = Reading road
Address_4 = NULL
Address_5 = NULL
City_d = NULL


The City column should be NULL because address1 does not match address_1.

Hope that helps.

Thanks


create table dbo.AddressSource
(Address1 varchar(50),
Address2 varchar(50),
Address3 varchar(50),
Address4 varchar(50),
Address5 varchar(50))

GO

Insert into dbo.AddressSource (
Address1,
Address2,
Address3,
Address4,
Address5

)

VALUES (
'67 office',
NULL,
'Reading road',
NULL,
NULL
)

Go


create table dbo.AddressDest
(Address_1 varchar(50),
Address_2 varchar(50),
Address_3 varchar(50),
Address_4 varchar(50),
Address_5 varchar(50),
City varchar(50),
WANTED_RESULTS varchar(200)) /* IF ANY OF THE ADDRESS1-5 LINE CHANGE or not change
and how it affects the CITY column*/

GO
--the result should only bring back one row- there two to show wanted results -
INSERT INTO AddressDest (Address_1,Address_2,Address_3,Address_4,Address_5,City,WANTED_RESULTS)
VALUES ('68 office',NULL,'Reading road',NULL,NULL,NULL,'one of the address column has changed the City is now NULL');
INSERT INTO AddressDest (Address_1,Address_2,Address_3,Address_4,Address_5,City,WANTED_RESULTS)
VALUES ('67 office',NULL,'Reading road',NULL,NULL,'London','nothing has changed in address1-5 the previous value will be used so London'
)

Post #1557920
Posted Thursday, April 3, 2014 12:59 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, August 18, 2014 2:46 AM
Points: 67, Visits: 554
No one got any ideas?
Post #1558192
Posted Friday, April 4, 2014 12:03 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:29 AM
Points: 13,570, Visits: 10,448
Using your conditional split, you have one output for when the has changed. Connect this to a derived column and set the city column to NULL.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1558371
Posted Friday, April 4, 2014 3:03 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 4:18 AM
Points: 2,048, Visits: 1,403
You could also use a 3rd party custom component such as the Checksum component from Konesans to calculate and store a checksum for the five address columns you are interested in and then compare the checksum of the source columns to the checksum of the destination columns; if the checksum values are different then at least one of your source columns has changed.

Disclaimer: I am not connected to Konesans in any way.

Regards
Lempster
Post #1558396
Posted Friday, April 4, 2014 3:50 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:29 AM
Points: 13,570, Visits: 10,448
Lempster (4/4/2014)
You could also use a 3rd party custom component such as the Checksum component from Konesans to calculate and store a checksum for the five address columns you are interested in and then compare the checksum of the source columns to the checksum of the destination columns; if the checksum values are different then at least one of your source columns has changed.

Disclaimer: I am not connected to Konesans in any way.

Regards
Lempster


You can also implement a hash yourself using a script component:
Using hash values in SSIS to determine when to insert or update rows




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1558409
Posted Friday, April 4, 2014 4:01 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:22 AM
Points: 5,035, Visits: 11,773
Lempster (4/4/2014)
You could also use a 3rd party custom component such as the Checksum component from Konesans to calculate and store a checksum for the five address columns you are interested in and then compare the checksum of the source columns to the checksum of the destination columns; if the checksum values are different then at least one of your source columns has changed.

Disclaimer: I am not connected to Konesans in any way.

Regards
Lempster


This is a good solution. For good performance, you should consider persisting the checksum as a new column in the target table(s).



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1558419
Posted Friday, April 4, 2014 6:12 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 4:18 AM
Points: 2,048, Visits: 1,403
Koen Verbeeck (4/4/2014)
You can also implement a hash yourself using a script component:
Using hash values in SSIS to determine when to insert or update rows

Yes and that would be my preferred way of doing it because you can use reduce the chance of hash collisions by using a stronger hash such as SHA1....but...the OP specifically stated that they didn't want to go down the scripting route.
Thanks for the link btw - I thought I had that saved to my favourites, but obviously not.
Post #1558459
Posted Friday, April 4, 2014 6:15 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:29 AM
Points: 13,570, Visits: 10,448
Lempster (4/4/2014)

....but...the OP specifically stated that they didn't want to go down the scripting route.


Yeah, but c'mon, all the c# code is already in the article :)




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1558462
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse