Introduction

According to MSDN, SSIS Services is a Microsoft Integration Service and a platform for building enterprise-level data integration and data transformations solutions. Use Integration Services to solve complex business problems by copying or downloading files, loading data warehouses, cleaning and mining data, and managing SQL Server objects and data.
Integration Services can extract and transform data from a wide variety of sources, such as XML data files, flat files, and relational data sources. They can then load the data into one or more destinations.
Prerequisites
  • Visual Studio
  • SharePoint Online account.
  • Basic knowledge of SharePoint.
To achieve our functionality, we have to follow these steps:
  • Create a list and add items to the list.
  • Create a database, table, and procedures in SQL Server
  • Create an SSIS Project in Visual Studio
  • Build and Deploy the solution
  • Schedule the SSIS packages.
Let begin.

Create a list and add an item in the list

For demonstration purposes, I have created two lists i.e Hobbies and Employee in SharePoint Online.
Hobbies - This list is a Master List
Load Data To A SQL Table From SharePoint List Using SSIS
Employee - This list consists of the lookup column (Hobbies) from the Hobbies master list.
Load Data To A SQL Table From SharePoint List Using SSIS
Load Data To A SQL Table From SharePoint List Using SSIS
This list consists of the following items.
Load Data To A SQL Table From SharePoint List Using SSIS
Now, we have the records in the list, let's create the database and table to load these records.

Create database, table, and procedures in SQL Server

To create a database, log into the SQL server with the proper credentials.
Load Data To A SQL Table From SharePoint List Using SSIS
Step 1
Select New Query from the menu and add this script (To execute script press F5)
create database SP_POC
Step 2
Once the database is created successfully, create two new tables for each list to holds employee and hobby records.
Employee List
Employee_Stage
This table will truncate weekly to holds all records for EmployeeFullPackage.dtsx as well as daily after every 15 min to holds new records for
EmployeeIncrementalPackage.dtsx
Employee
This table will truncate on weekly basis to holds all records for EmployeeFullPackage and updates daily after every 15 mins for EmployeeIncrementalPackage.dtsx
  1. CREATE TABLE Employee_Stage (
  2. ItemId int,
  3. FullName nvarchar(max),
  4. FirstName nvarchar(max),
  5. LastName nvarchar(max),
  6. PhoneNum int,
  7. Address nvarchar(max),
  8. Role nvarchar(max),
  9. IsActive nvarchar(max),
  10. Hobbies nvarchar(max),
  11. Created datetime,
  12. Modified datetime,
  13. CreatedById int,
  14. ModifiedById int,
  15. CreatedBy nvarchar(max),
  16. ModifiedBy nvarchar(max)
  17. );
  18. CREATE TABLE Employee (
  19. ItemId int,
  20. FullName nvarchar(max),
  21. FirstName nvarchar(max),
  22. LastName nvarchar(max),
  23. PhoneNum int,
  24. Address nvarchar(max),
  25. Role nvarchar(max),
  26. IsActive nvarchar(max),
  27. Hobbies nvarchar(max),
  28. Created datetime,
  29. Modified datetime,
  30. CreatedById int,
  31. ModifiedById int,
  32. CreatedBy nvarchar(max),
  33. ModifiedBy nvarchar(max)
  34. );
Hobbies List
Hobbies_Stage
This table will truncate weekly to holds all records for EmployeeFullPackage.dtsx as well as daily after every 15 min to holds new records for
EmployeeIncrementalPackage.dtsx
Hobbies
This table will truncate on weekly basis to hold all records for EmployeeFullPackage and updates daily after every 15 mins for EmployeeIncrementalPackage.dtsx
  1. CREATE TABLE Hobbies_Stage (
  2. ItemId int,
  3. Title nvarchar(max),
  4. Created datetime,
  5. Modified datetime,
  6. CreatedById int,
  7. ModifiedById int,
  8. CreatedBy nvarchar(max),
  9. ModifiedBy nvarchar(max)
  10. );
  11. CREATE TABLE Hobbies (
  12. ItemId int,
  13. Title nvarchar(max),
  14. Created datetime,
  15. Modified datetime,
  16. CreatedById int,
  17. ModifiedById int,
  18. CreatedBy nvarchar(max),
  19. ModifiedBy nvarchar(max)
  20. );
Load Data To A SQL Table From SharePoint List Using SSIS
Step 3
We required multiple stored procedures to insert or update records from stage to main table one for employee (i.e. From dbo.Employee_Stage to Employee) and another for hobbies.
EmployeeFullPackage - It will insert the records into the Employee table.
EmployeeIncrementalPackage - If the item is present in the Employee table, then it will update the records else will create the records.
Stored Procedures
A stored procedure is a group of one or more Transact-SQL statements into logical units, so that the statement can be reused over and over again.
Instead of writing an SQL query again and again, save it as a stored procedure, then just call it to execute it.
Write a new store procedure by right click on Stored Procedures -> New -> Store Procedure and paste the below scripts.
Stored Procedure for Employee - usp_MergeEmployee (Execute it by pressing F5).
  1. USE [SP_POC]
  2. GO
  3. -- ================================================
  4. -- Template generated from Template Explorer using:
  5. -- Create Procedure (New Menu).SQL
  6. --
  7. -- Use the Specify Values for Template Parameters
  8. -- command (Ctrl-Shift-M) to fill in the parameter
  9. -- values below.
  10. --
  11. -- This block of comments will not be included in
  12. -- the definition of the procedure.
  13. -- ================================================
  14. SET ANSI_NULLS ON
  15. GO
  16. SET QUOTED_IDENTIFIER ON
  17. GO
  18. -- =============================================
  19. -- Author: <Author,,Name>
  20. -- Create date: <Create Date,,>
  21. -- Description: <Description,,>
  22. -- =============================================
  23. CREATE PROCEDURE [dbo].[usp_MergeEmployee]
  24. AS
  25. BEGIN
  26. -- SET NOCOUNT ON added to prevent extra result sets from
  27. -- interfering with SELECT statements.
  28. SET NOCOUNT ON;
  29. -- Insert statements for procedure here
  30. BEGIN TRAN
  31. MERGE dbo.[Employee] AS dest
  32. USING dbo.[Employee_Stage] AS sour
  33. ON (dest.ItemID = sour.ItemID)
  34. WHEN MATCHED
  35. THEN UPDATE SET
  36. dest.[FullName] = sour.[FullName],
  37. dest.[FirstName] = sour.[FirstName],
  38. dest.[LastName] = sour.[LastName],
  39. dest.[PhoneNum] = sour.[PhoneNum],
  40. dest.[Address] = sour.[Address],
  41. dest.[Role] = sour.[Role],
  42. dest.[IsActive] = sour.[IsActive],
  43. dest.[Hobbies] = sour.[Hobbies],
  44. dest.[Created] = sour.[Created],
  45. dest.[CreatedById] = sour.[CreatedById],
  46. dest.[Modified] = sour.[Modified],
  47. dest.[ModifiedById] = sour.[ModifiedById],
  48. dest.[CreatedBy] = sour.[CreatedBy],
  49. dest.[ModifiedBy] = sour.[ModifiedBy]
  50. WHEN NOT MATCHED THEN
  51. INSERT (
  52. [ItemId]
  53. ,[FullName]
  54. ,[FirstName]
  55. ,[LastName]
  56. ,[PhoneNum]
  57. ,[Address]
  58. ,[Role]
  59. ,[IsActive]
  60. ,[Hobbies]
  61. ,[Created]
  62. ,[CreatedById]
  63. ,[Modified]
  64. ,[ModifiedById]
  65. ,[CreatedBy]
  66. ,[ModifiedBy]
  67. )
  68. VALUES ( sour.[ItemId]
  69. ,sour.[FullName]
  70. ,sour.[FirstName]
  71. ,sour.[LastName]
  72. ,sour.[PhoneNum]
  73. ,sour.[Address]
  74. ,sour.[Role]
  75. ,sour.[IsActive]
  76. ,sour.[Hobbies]
  77. ,sour.[Created]
  78. ,sour.[CreatedById]
  79. ,sour.[Modified]
  80. ,sour.[ModifiedById]
  81. ,sour.[CreatedBy]
  82. ,sour.[ModifiedBy]
  83. )
  84. OUTPUT $action, Inserted.*, Deleted.*;
  85. COMMIT TRAN
  86. END
Stored Procedure for Hobbies - usp_MergeHobbies (Execute it by pressing F5).
  1. USE [SP_POC]
  2. GO
  3. -- ================================================
  4. -- Template generated from Template Explorer using:
  5. -- Create Procedure (New Menu).SQL
  6. --
  7. -- Use the Specify Values for Template Parameters
  8. -- command (Ctrl-Shift-M) to fill in the parameter
  9. -- values below.
  10. --
  11. -- This block of comments will not be included in
  12. -- the definition of the procedure.
  13. -- ================================================
  14. SET ANSI_NULLS ON
  15. GO
  16. SET QUOTED_IDENTIFIER ON
  17. GO
  18. -- =============================================
  19. -- Author: <Author,,Name>
  20. -- Create date: <Create Date,,>
  21. -- Description: <Description,,>
  22. -- =============================================
  23. CREATE PROCEDURE [dbo].[usp_MergeHobbies]
  24. AS
  25. BEGIN
  26. -- SET NOCOUNT ON added to prevent extra result sets from
  27. -- interfering with SELECT statements.
  28. SET NOCOUNT ON;
  29. -- Insert statements for procedure here
  30. BEGIN TRAN
  31. MERGE dbo.[Hobbies] AS dest
  32. USING dbo.[Hobbies_Stage] AS sour
  33. ON (dest.ItemID = sour.ItemID)
  34. WHEN MATCHED
  35. THEN UPDATE SET
  36. dest.[Title] = sour.[Title],
  37. dest.[Created] = sour.[Created],
  38. dest.[CreatedById] = sour.[CreatedById],
  39. dest.[Modified] = sour.[Modified],
  40. dest.[ModifiedById] = sour.[ModifiedById],
  41. dest.[CreatedBy] = sour.[CreatedBy],
  42. dest.[ModifiedBy] = sour.[ModifiedBy]
  43. WHEN NOT MATCHED THEN
  44. INSERT (
  45. [ItemId]
  46. ,[Title]
  47. ,[Created]
  48. ,[CreatedById]
  49. ,[Modified]
  50. ,[ModifiedById]
  51. ,[CreatedBy]
  52. ,[ModifiedBy]
  53. )
  54. VALUES ( sour.[ItemId]
  55. ,sour.[Title]
  56. ,sour.[Created]
  57. ,sour.[CreatedById]
  58. ,sour.[Modified]
  59. ,sour.[ModifiedById]
  60. ,sour.[CreatedBy]
  61. ,sour.[ModifiedBy]
  62. )
  63. OUTPUT $action, Inserted.*, Deleted.*;
  64. COMMIT TRAN
  65. END
Load Data To A SQL Table From SharePoint List Using SSIS
In this article, we have completed the first two major steps.
Check the next part of this articles.
Load Data to an SQL Table from a SharePoint List Using SSIS - Part Two
Load Data to an SQL Table from a SharePoint List Using SSIS - Part Three