├── .gitattributes ├── 9781484242087.jpg ├── Contributing.md ├── LICENSE.txt ├── README.md ├── Sample Duplicate Detection Code └── Sample Duplicate Detection Code.sql ├── T-SQL Transfomation Code Library ├── Fn_Base64Decode.sql ├── Fn_Base64Encode.sql ├── fn_CamelCase.sql ├── fn_Convert15CharIDTo18.sql ├── fn_Fix_Invalid_XML_Chars.sql ├── fn_FormatPhone.sql ├── fn_Format_for_ContentNoteText.sql ├── fn_GetAccountAggregation - (Example for Multi Select Picklist ) .sql ├── fn_GetAddressLines.sql ├── fn_GetDomain.sql ├── fn_GetFileExtension.sql ├── fn_GetFileFromPath.sql ├── fn_GetNamePart.sql ├── fn_GoodEmailorBlank.sql ├── fn_MuliSelect_DedupAndSort.sql ├── fn_RemoveNonNumeric.sql ├── fn_StripHTML.sql ├── fn_StripNonAlphaNumericCharacters.sql ├── fn_StripSpaces.sql ├── fn_TextToHTML.sql └── sp_GetDirTree.sql ├── Thumbs.db └── errata.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /9781484242087.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/developing-data-migrations-and-integrations-with-salesforce/555329d633fbb3449d5e85fac72cb135012e5916/9781484242087.jpg -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Freeware License, some rights reserved 2 | 3 | Copyright (c) 2018 David Masri 4 | 5 | Permission is hereby granted, free of charge, to anyone obtaining a copy 6 | of this software and associated documentation files (the "Software"), 7 | to work with the Software within the limits of freeware distribution and fair use. 8 | This includes the rights to use, copy, and modify the Software for personal use. 9 | Users are also allowed and encouraged to submit corrections and modifications 10 | to the Software for the benefit of other users. 11 | 12 | It is not allowed to reuse, modify, or redistribute the Software for 13 | commercial use in any way, or for a user’s educational materials such as books 14 | or blog articles without prior permission from the copyright holder. 15 | 16 | The above copyright notice and this permission notice need to be included 17 | in all copies or substantial portions of the software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apress Source Code 2 | 3 | 4 | 5 | This repository accompanies [*Developing Data Migrations and Integrations with Salesforce*](http://www.apress.com/9781484242087) by David Masri (Apress, 2018). 6 | 7 | 8 | 9 | [comment]: #cover 10 | 11 | ![Cover image](9781484242087.jpg) 12 | 13 | 14 | 15 | Download the files as a zip using the green button, or clone the repository to your machine using Git. 16 | 17 | 18 | 19 | ## Releases 20 | 21 | 22 | 23 | Release v1.0 corresponds to the code in the published book, without corrections or updates. 24 | 25 | 26 | 27 | ## Contributions 28 | 29 | 30 | 31 | See the file Contributing.md for more information on how you can contribute to this repository. -------------------------------------------------------------------------------- /Sample Duplicate Detection Code/Sample Duplicate Detection Code.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/developing-data-migrations-and-integrations-with-salesforce/555329d633fbb3449d5e85fac72cb135012e5916/Sample Duplicate Detection Code/Sample Duplicate Detection Code.sql -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/Fn_Base64Decode.sql: -------------------------------------------------------------------------------- 1 | CREATE FUNCTION [dbo].[Fn_Base64Decode](@Input VARCHAR(MAX)) 2 | RETURNS VARCHAR(MAX) 3 | BEGIN 4 | DECLARE @DecodedOutput VARCHAR(MAX) 5 | set @DecodedOutput = cast('' as xml).value('xs:base64Binary(sql:variable("@Input"))', 'varbinary(max)') 6 | RETURN @DecodedOutput 7 | END 8 | -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/Fn_Base64Encode.sql: -------------------------------------------------------------------------------- 1 | CREATE FUNCTION [dbo].[Fn_Base64Encode](@Input VARCHAR(MAX)) 2 | RETURNS VARCHAR(MAX) 3 | BEGIN 4 | declare @source varbinary(max) 5 | declare @encoded varchar(max) 6 | set @source = convert(varbinary(max), @Input) 7 | set @encoded = cast('' as xml).value('xs:base64Binary(sql:variable("@source"))', 'varchar(max)') 8 | RETURN @encoded 9 | END 10 | GO -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_CamelCase.sql: -------------------------------------------------------------------------------- 1 | 2 | 3 | CREATE FUNCTION [dbo].[fn_CamelCase] (@InputString nvarchar(4000) ) 4 | RETURNS nVARCHAR(4000) 5 | AS 6 | BEGIN 7 | DECLARE @Index INT 8 | DECLARE @Char nCHAR(1) 9 | DECLARE @PrevChar nCHAR(1) 10 | DECLARE @OutputString nVARCHAR(255) 11 | 12 | SET @OutputString = LOWER(@InputString) 13 | SET @Index = 1 14 | 15 | WHILE @Index <= LEN(@InputString) 16 | BEGIN 17 | SET @Char = SUBSTRING(@InputString, @Index, 1) 18 | SET @PrevChar = CASE WHEN @Index = 1 THEN ' ' 19 | ELSE SUBSTRING(@InputString, @Index - 1, 1) 20 | END 21 | 22 | IF @PrevChar IN (' ', ';', ':', '!', '?', ',', '.', '_', '-', '/', '&', '''', '(') 23 | BEGIN 24 | IF @PrevChar != '''' OR UPPER(@Char) != 'S' 25 | SET @OutputString = STUFF(@OutputString, @Index, 1, UPPER(@Char)) 26 | END 27 | 28 | SET @Index = @Index + 1 29 | END 30 | RETURN @OutputString 31 | END 32 | -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_Convert15CharIDTo18.sql: -------------------------------------------------------------------------------- 1 | -- ============================================= 2 | -- Author: Joel Mansford 3 | -- Create date: Jan 2010 4 | -- Description: Converts 15char SF Ids to 18char ones 5 | -- History: 6 | -- June 2010 - issue with over-running and incorrectly producing ']' as a character with input such as '0033000000dGpDN' 7 | -- ============================================= 8 | 9 | CREATE FUNCTION dbo.fn_Convert15CharIDTo18 10 | ( @InputId char(15) 11 | ) 12 | RETURNS char(18) 13 | AS 14 | BEGIN 15 | -- Hacky way to raise an error but it works and there’s no alternative! 16 | DECLARE @ErrorStringReally int 17 | IF LEN(@InputId)<>15 18 | SET @ErrorStringReally ='Input Salesforce Id must be exactly 15 characters input was “'+ @InputId+'”' 19 | DECLARE @OutputId char(18) 20 | DECLARE @Hash varchar(3) 21 | SET @Hash = '' 22 | DECLARE @Chunk tinyint 23 | DECLARE @ThisChunk char(5) 24 | DECLARE @CharPos tinyint 25 | DECLARE @ThisHashDigit tinyint 26 | 27 | -- Split string in to 3 chunks of 5chars 28 | SET @Chunk = 1 29 | WHILE @Chunk<=3 30 | BEGIN 31 | SELECT @ThisChunk = RIGHT(LEFT(@InputId,@Chunk*5),5) 32 | SET @ThisHashDigit = 0 33 | SET @CharPos = 1 34 | -- Iterate over the chunk 35 | WHILE @CharPos<=5 36 | BEGIN 37 | IF ASCII(SUBSTRING(@ThisChunk,@CharPos,1)) BETWEEN 65 AND 90 -- If Uppercase 38 | -- then add a binary ’1′ digit in the appropriate position, otherwise it’s still 0 39 | SET @ThisHashDigit +=POWER(2,@CharPos-1) 40 | SET @CharPos+=1 41 | END 42 | IF @ThisHashDigit>=26 43 | -- Digits 0-9, minus 26 as SFDC have numbers come ‘after’ letters 44 | SET @Hash +=CHAR(@ThisHashDigit+48-26) 45 | ELSE 46 | -- Letter ‘A’ 47 | SET @Hash +=CHAR(@ThisHashDigit+65) 48 | SET @Chunk+=1 49 | END 50 | SET @OutputId = @InputId + @Hash 51 | RETURN @OutputId 52 | END -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_Fix_Invalid_XML_Chars.sql: -------------------------------------------------------------------------------- 1 | 2 | create Function [dbo].[fn_Fix_Invalid_XML_Chars](@strText NVARCHAR(max)) 3 | RETURNS NVARCHAR(max) 4 | AS 5 | BEGIN 6 | set @strText = replace(@strText,CHAR(0x0),'') 7 | set @strText = replace(@strText,CHAR(0x1),'') 8 | set @strText = replace(@strText,CHAR(0x2),'') 9 | set @strText = replace(@strText,CHAR(0x3),'') 10 | set @strText = replace(@strText,CHAR(0x4),'') 11 | set @strText = replace(@strText,CHAR(0x5),'') 12 | set @strText = replace(@strText,CHAR(0x6),'') 13 | set @strText = replace(@strText,CHAR(0x7),'') 14 | set @strText = replace(@strText,CHAR(0x8),'') 15 | set @strText = replace(@strText,CHAR(0x9),'') 16 | 17 | 18 | set @strText = replace(@strText,CHAR(0x10),'') 19 | set @strText = replace(@strText,CHAR(0x11),'') 20 | set @strText = replace(@strText,CHAR(0x12),'') 21 | set @strText = replace(@strText,CHAR(0x13),'') 22 | set @strText = replace(@strText,CHAR(0x14),'') 23 | set @strText = replace(@strText,CHAR(0x15),'') 24 | set @strText = replace(@strText,CHAR(0x16),'') 25 | set @strText = replace(@strText,CHAR(0x17),'') 26 | set @strText = replace(@strText,CHAR(0x18),'') 27 | set @strText = replace(@strText,CHAR(0x19),'') 28 | 29 | set @strText = replace(@strText,CHAR(0xa),'') 30 | set @strText = replace(@strText,CHAR(0xb),'') 31 | set @strText = replace(@strText,CHAR(0xc),'') 32 | set @strText = replace(@strText,CHAR(0xd),Char(10)) 33 | set @strText = replace(@strText,CHAR(0xe),'') 34 | set @strText = replace(@strText,CHAR(0xf),'') 35 | 36 | set @strText = replace(@strText,CHAR(0x1a),'''') 37 | set @strText = replace(@strText,CHAR(0x1b),'') 38 | set @strText = replace(@strText,CHAR(0x1c),'') 39 | set @strText = replace(@strText,CHAR(0x1d),'') 40 | set @strText = replace(@strText,CHAR(0x1e),'') 41 | set @strText = replace(@strText,CHAR(0x1f),'') 42 | 43 | set @strText = replace(@strText,CHAR(0x7f),'') 44 | 45 | RETURN @strText 46 | END 47 | 48 | 49 | 50 | 51 | GO 52 | 53 | 54 | -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_FormatPhone.sql: -------------------------------------------------------------------------------- 1 | Create Function [dbo].[fn_FormatPhone](@strTextFull nVARCHAR(1000)) 2 | RETURNS nVARCHAR(1000) 3 | AS 4 | BEGIN 5 | declare @strText nVARCHAR(1000) 6 | declare @strCleanText nVARCHAR(1000) 7 | declare @strTextExt nVARCHAR(1000) 8 | select @strTextExt='' 9 | 10 | --- 11 | select @strCleanText=replace(@strTextFull,' ','') 12 | select @strCleanText=replace(@strCleanText,'-','') 13 | select @strCleanText=replace(@strCleanText,'.','') 14 | select @strCleanText=replace(@strCleanText,'(','') 15 | select @strCleanText=replace(@strCleanText,')','') 16 | if SUBSTRING(@strCleanText,1,1)='+' ---------------- Remove Leading Plus 17 | select @strCleanText=SUBSTRING(@strCleanText,2,1000) 18 | if SUBSTRING(@strCleanText,1,1)='1' ---------------- Remove Leading 1 19 | select @strCleanText=SUBSTRING(@strCleanText,2,1000) 20 | 21 | -- for Extensions 22 | if SUBSTRING(@strCleanText,11,1)='x' or SUBSTRING(@strCleanText,11,1)='e' 23 | begin 24 | select @strTextExt=SUBSTRING(@strCleanText,11,1000) 25 | select @strCleanText=SUBSTRING(@strCleanText,1,10) 26 | end 27 | 28 | if isnumeric(@strCleanText)=0 29 | begin 30 | return @strTextFull-- No Transformation 31 | end 32 | 33 | if len(@strCleanText)<>10 34 | begin 35 | return @strTextFull -- No Transformation 36 | end 37 | 38 | select @strCleanText='('+substring(@strCleanText,1,3)+') '+substring(@strCleanText,4,3)+'-'+substring(@strCleanText,7,4) 39 | 40 | RETURN @strCleanText+' '+@strTextExt 41 | END -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_Format_for_ContentNoteText.sql: -------------------------------------------------------------------------------- 1 | Create Function [dbo].[fn_Format_for_ContentNoteText](@strText nVARCHAR(max)) 2 | RETURNS VARCHAR(max) 3 | AS 4 | BEGIN 5 | set @strText=replace(@strText,'&','&') 6 | set @strText=replace(@strText,'<','<') 7 | set @strText=replace(@strText,'>','>') 8 | set @strText=replace(@strText,'"','"') 9 | set @strText=replace(@strText,'''',''') 10 | set @strText=replace(@strText,char(9),' ') 11 | set @strText=replace(@strText,char(10),'
') 12 | set @strText=replace(@strText,char(23),'
') 13 | set @strText=replace(@strText,char(13),'
') 14 | 15 | RETURN coalesce(@strText,'') 16 | END 17 | -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_GetAccountAggregation - (Example for Multi Select Picklist ) .sql: -------------------------------------------------------------------------------- 1 | /****** Object: UserDefinedFunction [dbo].[fn_GetAccountAggregation] Script Date: 02/25/2015 16:10:16 ******/ 2 | SET ANSI_NULLS ON 3 | GO 4 | 5 | SET QUOTED_IDENTIFIER ON 6 | GO 7 | 8 | Create function [dbo].[fn_GetAccountAggregation](@companyID varchar(255)) 9 | returns nvarchar(1000) 10 | begin 11 | declare @CommaString nvarchar(max) 12 | set @CommaString='' 13 | select @CommaString +=rtrim(ltrim(Type)) +';' from dbo.companytype where companyID=@companyID -- Modify this SQL 14 | if len(@CommaString)>0 15 | begin 16 | -- Drop Extra Semi-Colon 17 | SET @CommaString = LEFT(@CommaString, LEN(@CommaString) - 1) 18 | end 19 | Return @CommaString 20 | end 21 | 22 | GO 23 | 24 | 25 | -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_GetAddressLines.sql: -------------------------------------------------------------------------------- 1 | 2 | 3 | Create function [dbo].[fn_GetAddressLines](@Address nVarchar(3000),@Linepart Char(2)) 4 | returns nvarchar(1000) 5 | -- @Linepart : L1=First,L2=L3=Last 6 | begin 7 | 8 | Declare @Line1 nVarchar(3000) 9 | Declare @Line2 nVarchar(3000) 10 | Declare @Line3 nVarchar(3000) 11 | Declare @Return nVarchar(3000) 12 | 13 | select @Address=rtrim(ltrim(coalesce(@Address,''))) 14 | SELECT @Line1= rtrim(ltrim(coalesce(@Address,''))) 15 | SELECT @Line2='' 16 | SELECT @Line3='' 17 | 18 | 19 | if @Address like '%'+char(10)+'%' 20 | Begin 21 | SELECT @Line1= SUBSTRING(@Address, 1, CHARINDEX(Char(10), @Address) - 1) 22 | SELECT @Line2=substring(replace(@Address,@Line1,''),2,3000) 23 | end 24 | 25 | select @Address=@Line2 26 | 27 | if @Address like '%'+char(10)+'%' 28 | Begin 29 | SELECT @Line2= SUBSTRING(@Address, 1, CHARINDEX(Char(10), @Address) - 1) 30 | SELECT @Line3=substring(replace(@Address,@Line2,''),2,3000) 31 | SELECT @Line3=replace(@Line3,char(10),'-') 32 | end 33 | 34 | SELECT @Return = case when @Linepart = 'L1' then @Line1 35 | when @Linepart = 'L2' then @Line2 36 | when @Linepart = 'L3' then @Line3 37 | else Null end 38 | 39 | Return rtrim(ltrim(@Return)) 40 | end -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_GetDomain.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/developing-data-migrations-and-integrations-with-salesforce/555329d633fbb3449d5e85fac72cb135012e5916/T-SQL Transfomation Code Library/fn_GetDomain.sql -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_GetFileExtension.sql: -------------------------------------------------------------------------------- 1 | CREATE Function [dbo].[fn_GetFileExtension](@FileName nVARCHAR(1000)) 2 | RETURNS nVARCHAR(1000) 3 | AS 4 | BEGIN 5 | Return 6 | case when substring(right(@FileName,4),1,1)='.' then right(@FileName,4) 7 | when substring(right(@FileName,5),1,1)='.' then right(@FileName,5) 8 | else '' 9 | end 10 | END -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_GetFileFromPath.sql: -------------------------------------------------------------------------------- 1 | /****** Object: UserDefinedFunction [dbo].[fn_GetFileFromPath] Script Date: 02/25/2015 16:09:41 ******/ 2 | SET ANSI_NULLS ON 3 | GO 4 | 5 | SET QUOTED_IDENTIFIER ON 6 | GO 7 | 8 | CREATE Function [dbo].[fn_GetFileFromPath](@PathFile NVARCHAR(1000)) 9 | RETURNS NVARCHAR(1000) 10 | AS 11 | BEGIN 12 | declare @FileName NVARCHAR(1000) 13 | SELECT @PathFile='\'+replace(@PathFile,'/','\') -- For Unix Type Paths 14 | SELECT @FileName=reverse(left(reverse(@PathFile), 15 | charindex('\',reverse(@PathFile), 16 | 1) - 1)) 17 | RETURN @FileName 18 | END 19 | 20 | 21 | 22 | 23 | 24 | GO 25 | 26 | 27 | -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_GetNamePart.sql: -------------------------------------------------------------------------------- 1 | 2 | 3 | CREATE function [dbo].[fn_GetNamePart](@FullName NVarchar(3000),@Namepart Char(1)) 4 | returns Nvarchar(1000) 5 | -- @Namepart : F=First,M=Middle,L=Last 6 | begin 7 | Declare @FirstName Varchar(1000) 8 | Declare @MiddleName Varchar(1000) 9 | Declare @LastName Varchar(1000) 10 | Declare @Return Varchar(1000) 11 | 12 | select @FullName=rtrim(ltrim(coalesce(@FullName,'')))+' ' 13 | SELECT @FirstName= SUBSTRING(@FullName, 1, CHARINDEX(' ', @FullName) - 1) 14 | 15 | select @FullName=' '+rtrim(ltrim(@FullName)) 16 | SELECT @LastName= REVERSE(SUBSTRING(REVERSE(@FullName), 1, CHARINDEX(' ', REVERSE(@FullName)) - 1)) 17 | SELECT @MiddleName=replace(replace(@FullName,@FirstName,''),@LastName,'') 18 | 19 | SELECT @Return = case when @Namepart = 'F' then @FirstName 20 | when @Namepart = 'M' then @MiddleName 21 | when @Namepart = 'L' then @LastName 22 | else Null end 23 | 24 | Return rtrim(ltrim(@Return)) 25 | end 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_GoodEmailorBlank.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/developing-data-migrations-and-integrations-with-salesforce/555329d633fbb3449d5e85fac72cb135012e5916/T-SQL Transfomation Code Library/fn_GoodEmailorBlank.sql -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_MuliSelect_DedupAndSort.sql: -------------------------------------------------------------------------------- 1 | Create FUNCTION dbo.fn_MuliSelect_DedupAndSort(@List nVARCHAR(MAX)) 2 | RETURNS nVARCHAR(MAX) 3 | AS 4 | BEGIN 5 | DECLARE @Delim CHAR=';' 6 | 7 | DECLARE @ParsedList TABLE 8 | ( 9 | Item nVARCHAR(MAX) 10 | ) 11 | DECLARE @list1 nVARCHAR(MAX), @Pos INT, @rList nVARCHAR(MAX) 12 | SET @list = LTRIM(RTRIM(@list)) + @Delim 13 | SET @pos = CHARINDEX(@delim, @list, 1) 14 | WHILE @pos > 0 15 | BEGIN 16 | SET @list1 = LTRIM(RTRIM(LEFT(@list, @pos - 1))) 17 | IF @list1 <> '' 18 | INSERT INTO @ParsedList VALUES (CAST(@list1 AS nVARCHAR(MAX))) 19 | SET @list = SUBSTRING(@list, @pos+1, LEN(@list)) 20 | SET @pos = CHARINDEX(@delim, @list, 1) 21 | END 22 | SELECT 23 | @rlist = COALESCE(@rlist+@Delim,'') + item 24 | FROM (SELECT DISTINCT Item FROM @ParsedList) t 25 | RETURN @rlist 26 | END 27 | GO -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_RemoveNonNumeric.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/developing-data-migrations-and-integrations-with-salesforce/555329d633fbb3449d5e85fac72cb135012e5916/T-SQL Transfomation Code Library/fn_RemoveNonNumeric.sql -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_StripHTML.sql: -------------------------------------------------------------------------------- 1 | CREATE FUNCTION [dbo].[fn_StripHTML] (@HTMLText nVARCHAR(MAX)) 2 | RETURNS nVARCHAR(MAX) AS 3 | BEGIN 4 | DECLARE @Start INT 5 | DECLARE @End INT 6 | DECLARE @Length INT 7 | SET @HTMLText=replace(@HTMLText,'
',Char(10)) 8 | SET @HTMLText=replace(@HTMLText,'
',Char(10)) 9 | SET @HTMLText=replace(@HTMLText,' ',' ') 10 | SET @HTMLText=replace(@HTMLText,'’','''') 11 | SET @HTMLText=replace(@HTMLText,'&','&') 12 | SET @HTMLText=replace(@HTMLText,'"','"') 13 | 14 | 15 | SET @Start = CHARINDEX('<',@HTMLText) 16 | SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText)) 17 | SET @Length = (@End - @Start) + 1 18 | WHILE @Start > 0 AND @End > 0 AND @Length > 0 19 | BEGIN 20 | SET @HTMLText = STUFF(@HTMLText,@Start,@Length,'') 21 | SET @Start = CHARINDEX('<',@HTMLText) 22 | SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText)) 23 | SET @Length = (@End - @Start) + 1 24 | END 25 | --- For MS Dynamics or Emails 26 | SET @HTMLText=replace(@HTMLText,'{behavior:url(#default#VML);}','') 27 | SET @HTMLText=replace(@HTMLText,'v\:*','') 28 | SET @HTMLText=replace(@HTMLText,'o\:*','') 29 | SET @HTMLText=replace(@HTMLText,'w\:*','') 30 | SET @HTMLText=replace(@HTMLText,'.shape','') 31 | SET @HTMLText=replace(@HTMLText,'.shape','') 32 | RETURN LTRIM(RTRIM(@HTMLText)) 33 | END 34 | GO -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_StripNonAlphaNumericCharacters.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/developing-data-migrations-and-integrations-with-salesforce/555329d633fbb3449d5e85fac72cb135012e5916/T-SQL Transfomation Code Library/fn_StripNonAlphaNumericCharacters.sql -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_StripSpaces.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/developing-data-migrations-and-integrations-with-salesforce/555329d633fbb3449d5e85fac72cb135012e5916/T-SQL Transfomation Code Library/fn_StripSpaces.sql -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/fn_TextToHTML.sql: -------------------------------------------------------------------------------- 1 | CREATE Function [dbo].[fn_TextToHTML](@strText nVARCHAR(max)) 2 | RETURNS VARCHAR(max) 3 | AS 4 | BEGIN 5 | set @strText=replace(@strText,'&','&') 6 | set @strText=replace(@strText,'<','<') 7 | set @strText=replace(@strText,'>','>') 8 | set @strText=replace(@strText,'"','"') 9 | set @strText=replace(@strText,'''',''') 10 | set @strText=replace(@strText,char(9),' ') 11 | set @strText=replace(@strText,char(10),'
') 12 | set @strText=replace(@strText,char(23),'
') 13 | set @strText=replace(@strText,char(13),'
') 14 | 15 | RETURN '
'+coalesce(@strText,'')+'
' 16 | END 17 | -------------------------------------------------------------------------------- /T-SQL Transfomation Code Library/sp_GetDirTree.sql: -------------------------------------------------------------------------------- 1 | Create Procedure [dbo].[sp_GetDirTree](@BackupDirectory varchar(4000)) as 2 | begin 3 | IF OBJECT_ID('tempdb..#DirTree') IS NOT NULL 4 | DROP TABLE #DirTree 5 | 6 | IF OBJECT_ID('tempdb..#ParentDirectoryIDs') IS NOT NULL 7 | DROP TABLE #ParentDirectoryIDs 8 | 9 | CREATE TABLE #DirTree ( 10 | Id int identity(1,1), 11 | SubDirectory nvarchar(255), 12 | Depth smallint, 13 | FileFlag bit, 14 | ParentDirectoryID int 15 | ) 16 | 17 | INSERT INTO #DirTree (SubDirectory, Depth, FileFlag) 18 | EXEC master..xp_dirtree @BackupDirectory, 10, 1 19 | 20 | UPDATE #DirTree 21 | SET ParentDirectoryID = ( 22 | SELECT MAX(Id) FROM #DirTree d2 23 | WHERE Depth = d.Depth - 1 AND d2.Id < d.Id 24 | ) 25 | FROM #DirTree d 26 | 27 | DECLARE 28 | @ID INT, 29 | @BackupFile VARCHAR(MAX), 30 | @Depth TINYINT, 31 | @FileFlag BIT, 32 | @ParentDirectoryID INT, 33 | @wkSubParentDirectoryID INT, 34 | @wkSubDirectory VARCHAR(MAX) 35 | 36 | DECLARE @BackupFiles TABLE 37 | ( 38 | FileNamePath VARCHAR(MAX), 39 | TransLogFlag BIT, 40 | BackupFile VARCHAR(MAX), 41 | DatabaseName VARCHAR(MAX) 42 | ) 43 | 44 | DECLARE FileCursor CURSOR LOCAL FORWARD_ONLY FOR 45 | SELECT * FROM #DirTree WHERE FileFlag = 1 46 | 47 | OPEN FileCursor 48 | FETCH NEXT FROM FileCursor INTO 49 | @ID, 50 | @BackupFile, 51 | @Depth, 52 | @FileFlag, 53 | @ParentDirectoryID 54 | 55 | SET @wkSubParentDirectoryID = @ParentDirectoryID 56 | 57 | WHILE @@FETCH_STATUS = 0 58 | BEGIN 59 | --loop to generate path in reverse, starting with backup file then prefixing subfolders in a loop 60 | WHILE @wkSubParentDirectoryID IS NOT NULL 61 | BEGIN 62 | SELECT @wkSubDirectory = SubDirectory, @wkSubParentDirectoryID = ParentDirectoryID 63 | FROM #DirTree 64 | WHERE ID = @wkSubParentDirectoryID 65 | 66 | SELECT @BackupFile = @wkSubDirectory + '\' + @BackupFile 67 | END 68 | 69 | --no more subfolders in loop so now prefix the root backup folder 70 | SELECT @BackupFile = @BackupDirectory + @BackupFile 71 | 72 | --put backupfile into a table and then later work out which ones are log and full backups 73 | INSERT INTO @BackupFiles (FileNamePath) VALUES(@BackupFile) 74 | 75 | FETCH NEXT FROM FileCursor INTO 76 | @ID, 77 | @BackupFile, 78 | @Depth, 79 | @FileFlag, 80 | @ParentDirectoryID 81 | 82 | SET @wkSubParentDirectoryID = @ParentDirectoryID 83 | END 84 | 85 | CLOSE FileCursor 86 | DEALLOCATE FileCursor 87 | -- Populate Full Path 88 | alter table #DirTree add Full_Path varchar(4000) 89 | 90 | declare @minID int 91 | declare @currPath varchar(4000) 92 | 93 | 94 | update #DirTree set Full_Path='' 95 | 96 | Select distinct ParentDirectoryID 97 | into #ParentDirectoryIDs 98 | from #DirTree 99 | where ParentDirectoryID is not null 100 | --and id<15 101 | 102 | 103 | WHILE (select count(1) from #ParentDirectoryIDs) > 0 104 | begin 105 | select @minID=min(ParentDirectoryID) from #ParentDirectoryIDs 106 | select @currPath=Full_Path+SubDirectory from #DirTree where id= @minID 107 | 108 | Update #DirTree set Full_Path=Full_Path+'\'+@currPath where ParentDirectoryID=@minID and ParentDirectoryID is not null 109 | 110 | delete from #ParentDirectoryIDs where ParentDirectoryID=@minID 111 | end 112 | update #DirTree set Full_Path=Full_Path+'\'+SubDirectory 113 | 114 | select * from #DirTree 115 | 116 | IF OBJECT_ID('tempdb..#DirTree') IS NOT NULL 117 | DROP TABLE #DirTree 118 | 119 | IF OBJECT_ID('tempdb..#ParentDirectoryIDs') IS NOT NULL 120 | DROP TABLE #ParentDirectoryIDs 121 | 122 | end 123 | GO 124 | 125 | 126 | -------------------------------------------------------------------------------- /Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/developing-data-migrations-and-integrations-with-salesforce/555329d633fbb3449d5e85fac72cb135012e5916/Thumbs.db -------------------------------------------------------------------------------- /errata.md: -------------------------------------------------------------------------------- 1 | # Errata for *Developing Data Migrations and Integrations with Salesforce* 2 | 3 | On **page xx** [Summary of error]: 4 | 5 | Details of error here. Highlight key pieces in **bold**. 6 | 7 | *** 8 | 9 | On **page xx** [Summary of error]: 10 | 11 | Details of error here. Highlight key pieces in **bold**. 12 | 13 | *** --------------------------------------------------------------------------------