This script assists with the creation of the Conditional Split “Changed Rows” conditional expression for an incremental load in SSIS packages.
Simply copy and paste the output.
I must admit that I unashamedly copied the original script from David R Buckingham (many thanks) on SQLBlog.com and here’s the link to the original).
However, here I modified it to deal with multiple datatypes since editing and debugging in the “Conditional Split Transformation Editor” needs much improvement.
/*
This script assists with the creation of the Conditional Split “Changed Rows” condition
— be sure your results aren’t being truncated when you have a table with many columns
*/
— BEGIN SCRIPT —
USE master
GO
DECLARE @Filter varchar(max)
SET @Filter = ”
SELECT @Filter = @Filter + ‘((ISNULL(‘ + c.[name] + ‘)?’+
CASE WHEN c.system_type_id IN (35,104,167,175,231,239,241) THEN ‘””‘
WHEN c.system_type_id IN (58,61) THEN ‘(DT_DBTIMESTAMP)”1900-01-01″‘
ELSE ‘0’ END
+ ‘:’ + c.[name] + ‘)!=(ISNULL(Dest_’ + c.[name] + ‘)?’ +
CASE WHEN c.system_type_id IN (35,104,167,175,231,239,241) THEN ‘””‘
WHEN c.system_type_id IN (58,61) THEN ‘(DT_DBTIMESTAMP)”1900-01-01″‘
ELSE ‘0’ END
+’:Dest_’ + c.[name] + ‘)) || ‘
FROM sys.tables t
INNER JOIN sys.columns c
ON t.[object_id] = c.[object_id]
WHERE SCHEMA_NAME( t.[schema_id] ) = ‘dbo’ — enter tour schema name here
AND t.[name] = ‘MyTable’ — enter your table name here
AND c.[is_identity] = 0
AND c.[is_rowguidcol] = 0
ORDER BY
c.[column_id]
SET @Filter = LEFT(@Filter, (LEN(@Filter) – 2))
SELECT @Filter
–SELECT
— c.*
–FROM
— sys.tables t
–JOIN
— sys.columns c
— ON t.[object_id] = c.[object_id]
–WHERE
— SCHEMA_NAME( t.[schema_id] ) = ‘dbo’
–AND t.[name] = ‘DimUPRTable’
–AND c.[is_identity] = 0
–AND c.[is_rowguidcol] = 0
–ORDER BY
–c.[column_id]
–SELECT
— schemas.name AS [Schema]
— ,tables.name AS [Table]
— ,columns.name AS [Column]
— ,CASE WHEN columns.system_type_id = 34
— THEN ‘byte[]’
— WHEN columns.system_type_id = 35
— THEN ‘string’
— WHEN columns.system_type_id = 36
— THEN ‘System.Guid’
— WHEN columns.system_type_id = 48
— THEN ‘byte’
— WHEN columns.system_type_id = 52
— THEN ‘short’
— WHEN columns.system_type_id = 56
— THEN ‘int’
— WHEN columns.system_type_id = 58
— THEN ‘System.DateTime’
— WHEN columns.system_type_id = 59
— THEN ‘float’
— WHEN columns.system_type_id = 60
— THEN ‘decimal’
— WHEN columns.system_type_id = 61
— THEN ‘System.DateTime’
— WHEN columns.system_type_id = 62
— THEN ‘double’
— WHEN columns.system_type_id = 98
— THEN ‘object’
— WHEN columns.system_type_id = 99
— THEN ‘string’
— WHEN columns.system_type_id = 104
— THEN ‘bool’
— WHEN columns.system_type_id = 106
— THEN ‘decimal’
— WHEN columns.system_type_id = 108
— THEN ‘decimal’
— WHEN columns.system_type_id = 122
— THEN ‘decimal’
— WHEN columns.system_type_id = 127
— THEN ‘long’
— WHEN columns.system_type_id = 165
— THEN ‘byte[]’
— WHEN columns.system_type_id = 167
— THEN ‘string’
— WHEN columns.system_type_id = 173
— THEN ‘byte[]’
— WHEN columns.system_type_id = 175
— THEN ‘string’
— WHEN columns.system_type_id = 189
— THEN ‘long’
— WHEN columns.system_type_id = 231
— THEN ‘string’
— WHEN columns.system_type_id = 239
— THEN ‘string’
— WHEN columns.system_type_id = 241
— THEN ‘string’
— WHEN columns.system_type_id = 241
— THEN ‘string’
— END AS [Type]
— ,columns.is_nullable AS [Nullable]
–FROM
— sys.tables tables
–INNER JOIN
— sys.schemas schemas
–ON (tables.schema_id = schemas.schema_id )
–INNER JOIN
— sys.columns columns
–ON (columns.object_id = tables.object_id)
–WHERE
— tables.name <> ‘sysdiagrams’
— AND tables.name <> ‘dtproperties’
–ORDER BY
— [Schema]
— ,[Table]
— ,[Column]
— ,[Type]