Wednesday, June 27, 2012

Performing Control Flow task in SSIS Package

Steps to create Control Flow in SSIS package


Below is an example design for control flow
Get a SQL task and name it as 'SQL Insert Audit' to insert audit values and update the script in 'SQL Statement' field as given below:
exec spu_insert_audit ?,?, ?,?,?,? OUT

and go to the Parameter Mapping option and add the variables as shown below:
next, get a SQL task and name it as 'SQL Drop All FK' and update the script in 'SQL Statement' field as given below:
exec [dbo].[sp_ExecDropAndRebuildSql]  '','','drop','r' 

now get an 'Execute Package Task' and name it as 'EPT package_name'. In that, go to Package option and select the Location field as 'File System'. In Connection field, select the package name. See below:
now go to the variable option and create variables as shown below:
here the value path for the variable name 'sPkgFolder' is the place where the packages saved.

next we can see the package_name.dtsx created in the Connection Managers area. Select the package name and press F4 to go to the property window.
In Property window, go to the Expression field and select the property as 'ConnectionString' and expression as '@[User::sPkgFolder]+ @[User::sPkgFileNameStaging]'.  Drag the variables from the available list and form the script. Click the Evaluate Expression' button to confirm the expression. See below screen:

do the same step to connect all the packages in control flow as showed in the example design of control flow package in top.

Finally need to get a SQL task to rebuild the Foreign Key. Get a SQL task and name it as 'SQL Rebuild All FK' and update the script in 'SQL Statement' field as given below:
exec [dbo].[sp_ExecDropAndRebuildSql]  '','','create','F'

Performing Audit Task Summary in SSIS Package

Step to create Audit Task Summary package in SSIS


Get DFT Task and name it as "DFT_Load DBName_AuditTaskSummary".
Get into the DFT task and Design package as given below:
Now get into the OLE_Source task and write the SQL command text as given below to get the audit data from AuditTask table.

SELECT GETDATE() AS SummaryDate
              ,MAX(AuditTaskId) AS maxAuditTaskId
              ,MAX(AuditId) AS MaxAuditId
              ,PackageName
             ,TableName
 FROM dbo.AuditTask
 GROUP BY PackageName , TableName


Next, go to lookup task and name it as 'LKP AuditTaskSummary and set as "Redirect rows to no match output" to handle rows with no matching entries.
Go to 'Connection' option and write the below query in "Use results of an SQL query:" filed.


SELECT TableName
              ,PackageName
  FROM dbo.AuditTaskSummary


Next go to the 'Columns' option and map the cloumns as shown below:
From Lookup task, connect the Lookup Match Output to 'OLE DB Command' task. In that task, go the 'Component Properties' section and write the below query in the SqlCommand field.

Update dbo.AuditTaskSummary 
 Set SummaryDate = getDate(),
       MaxAuditTaskId = ?
where tableName = ? and PackageName = ?


And go to 'Column Mapping' section and map the columns as shown below. Check the exact data type match before map it.
Next, from the Lookup task, connect the Lookup No Match Output to 'OLE Destination named as 'OLE Dest_AuditTaskSummary' through Row Count task. Select the 'dbo.AuditTaskSummary' table and map the columns accordingly.

Performing Audit Function in Event Handlers in SSIS Package


Steps and scripts to create Audit function in Event Handlers tab in a SSIS package.

Create variables in package for declared values

--In the Event Handlers tab – do the below steps

Select "OnTaskFailed" - get Script Task and name it as 'SRC SetOnTaskFailed'– in the ReadWriteVariables option – select "User::Status" and this User::Status should be created in variable as "Status" and the value as "Completed".

And go to Edit Script option – write the below query

public void Main()
{
// TODO: Add your code here
Dts.Variables["User::Status"].Value = "OnTaskFailed";
Dts.TaskResult = (int)ScriptResults.Success;
}

Select "OnError" - get Script Task and name it as 'SRC SetOnError'– in the ReadWriteVariables option – select "User::Status" and this User::Status should be created in variable as "Status" and the value as "Completed".

And go to Edit Script option – write the below query

public void Main()
{
// TODO: Add your code here
Dts.Variables["User::Status"].Value = "OnError";
Dts.TaskResult = (int)ScriptResults.Success;
}

From the SRC SetOnError – get a line to connect an Exe SQL task and name it as 'SQL Recreate PK_Index_of_Target'.

In connector – select the Evalution Operation as "Constraint"
and Value as "Success".

Also select the Multiple Constraints with "OR" option.

And connect line to – "SQL Recreate PK_Index_of_Target" (Exe SQL Task)

In which, do as below:

--write the below script to insert values in Audit
EXEC [dbo].[sp_ExecDropAndRebuildSql] ?, ?, 'create', 'p,i'

And go the Parameter Mapping option and select as below

variableName      Direction    DataType  ParameterName  ParameterSize
User::SchemaName  Input      Varchar          0                   -1
User::TableName     Input      Varchar          1                   -1

Select "OnPreExecute" – get Script Task - In the ReadOnlyVariables option – select "System::SourceName,Uder::AuditId,System::PackageName" and in the ReadWriteVariables option – select "User::IsPackageLevel,User::IsParentValue" and this User::IsPackageLevel,User::IsParentValue and UserAuditId should be created in variable as "IsPackageLevel" with value as "False","IsParentValue" with value as "False" and "AuditId" with value as "-1".

And go to Edit Script option – write the below query

public void Main()
{
// TODO: Add your code here
if (Dts.Variables["System::SourceName"].Value.Equals(Dts.Variables["System::PackageName"].Value))
{
Dts.Variables["User::IsPackageLevel"].Value = true;
if ((int)Dts.Variables["User::AuditId"].Value == -1)
{
Dts.Variables["User::IsParentValue"].Value = false;
}
else
{
Dts.Variables["User::IsParentValue"].Value = true;
}
}
else
{

Dts.Variables["User::IsPackageLevel"].Value = false;
}

Dts.TaskResult = (int)ScriptResults.Success;
}

From the SRC Intial – get two line to connect two Exe SQL task

"SQL Insert [DBName]_Audit (AND) SQL Insert [DBName]_AuditTask"

In connector I – select the Evalution Operation as "Expression and Constraint"
and Value as "Success" and Expression as "@IsPackageLevel && !@IsParentValue".

Also select the Multiple Constraints with "AND" option.

And connect line to – "SQL Insert Imports_Audit" (Exe SQL Task)

In which, do as below:

--write the below script to insert values in Audit
exec spu_insert_audit ?,?, ?,?,?,? OUT

And go the Parameter Mapping option and select as below

variable Name            Direction   DataType  ParameterName  ParameterSize
User::AuditId              Output       Long             5                      -1
System::StartTime       Input         Date             0                      -1
System::Versionbuild   Input          Long             1                     -1
System::UserName       Input        Varchar          2                      -1
System::PackageName Input         Varchar          3                      -1
System::MachineName Input         Varchar          4                      -1

In connector II – select the Evalution Operation as "Expression and Constraint"
and Value as "Success" and Expression as

"!(SUBSTRING(@[System::SourceName],1,4)=="FELC") && ! (SUBSTRING(@[System::SourceName],1,3)=="SRC") && !@IsPackageLevel".

Also select the Multiple Constraints with "AND" option.

And connect line to – "SQL Update Imports_AuditTask" (Exe SQL Task)

In which, do as below:

--write the below script to insert values in AuditTask
exec spu_insert_audit_task ?,?,?,?,?,?,?,?,? OUT

And go the Parameter Mapping option and select as below

variable Name             Direction   DataType   ParameterName   ParameterSize
User::AuditId                Input         Long              0                     -1
User::AuditTaskId          Output       Long             8                      -1
System::StartTime         Input         Date              1                     -1
System::Versionbuild     Input         Long              2                      -1
System::UserName        Input        Varchar           3                      -1
System::PackageName   Input        Varchar           4                      -1
System::MachineName    Input       Varchar           5                      -1
System::SourceName      Input       Varchar           6                       -1
User::TableName           Input        Varchar          7                       -1

Select "OnPostExecute" – get Script Task - In the ReadOnlyVariable option – select "System::SourceName,System::PackageName" and in the ReadWriteVariables option – select "User::IsPackageLevel" and this User::IsPackageLevel should be created in variable as "IsPackageLevel" and the value as "False".

And go to Edit Script option – write the below query

public void Main()
{
// TODO: Add your code here
if (Dts.Variables["System::SourceName"].Value.Equals(Dts.Variables["System::PackageName"].Value))
{
Dts.Variables["User::IsPackageLevel"].Value = true;
}
else
{
Dts.Variables["User::IsPackageLevel"].Value = false;
}
Dts.TaskResult = (int)ScriptResults.Success;
}

From the SRC IsPackageLevel – get two line to connect two Exe SQL task

"SQL Update [DBName]_Audit (AND) SQL Update [DBName]_AuditTask"

In connector I – select the Evalution Operation as "Expression and Constraint"
and Value as "Success" and Expression as "@IsPackageLevel && !@IsParentValue".

Also select the Multiple Constraints with "AND" option.

And connect line to – "SQL Update Imports_Audit" (Exe SQL Task)

In which, do as below:

--write the below script to update values in Audit
UPDATE [dbo].[Audit]
SET [Status] = 'Completed'
,[EndTime] = GETDATE()
Where AuditId= -1
GO

Go to Expression – select the "SqlStatementSource" option and write below query:

"UPDATE [dbo].[Audit]
SET [Status] = '"+ @[User::Status] +"'
,[EndTime] = GETDATE()
Where AuditId= "+ (DT_WSTR, 20) (@[User::AuditId]) +"
GO
"

In connector II – select the Evalution Operation as "Expression and Constraint"
and Value as "Success" and Expression as "!@IsPackageLevel".

Also select the Multiple Constraints with "AND" option.

And connect line to – "SQL Update Imports_AuditTask" (Exe SQL Task)

In which, do as below:

--write the below script to update values in AuditTask
UPDATE [dbo].[AuditTask]
SET [Status] = 'Completed'
,[EndTime] = GETDATE()
,[RowsAffected]= 0
,[LastModDate]=''
Where AuditTaskId= '0'
GO

Go to Expression – select the "SqlStatementSource" option and write below query:

"UPDATE [dbo].[AuditTask]
SET [Status] = '"+@[User::Status]+"'
,[EndTime] = GETDATE()
,[RowsAffected]= "+ (DT_WSTR, 20)( @[User::RowsAffected]) +"
,[LastModDate]='"+@[User::LastModDate] +"'
Where AuditTaskId= '"+ (DT_WSTR, 20)(@[User::AuditTaskId]) +"'
GO"

==================================================

To Create Audit function in Control flow

--In the Event Handlers tab – do the below steps

Select "OnTaskFailed" - get Script Task – in the ReadWriteVariables option – select "User::Status" and this User::Status should be created in variable as "Status" and the value as "Completed".

And go to Edit Script option – write the below query

public void Main()
{
// TODO: Add your code here
Dts.Variables["User::Status"].Value = "OnTaskFailed";
Dts.TaskResult = (int)ScriptResults.Success;
}

Select "OnError" - get Script Task – in the ReadWriteVariables option – select "User::Status" and this User::Status should be created in variable as "Status" and the value as "Completed".

And go to Edit Script option – write the below query

public void Main()
{
// TODO: Add your code here
Dts.Variables["User::Status"].Value = "OnError";
Dts.TaskResult = (int)ScriptResults.Success;
}

Select "OnPostExecute" – get Script Task - In the ReadOnlyVariable option – select "System::SourceName,System::PackageName" and in the ReadWriteVariables option – select "User::IsPackageLevel" and this User::IsPackageLevel should be created in variable as "IsPackageLevel" and the value as "False".

And go to Edit Script option – write the below query

public void Main()
{
// TODO: Add your code here
if (Dts.Variables["System::SourceName"].Value.Equals(Dts.Variables["System::PackageName"].Value))
{
Dts.Variables["User::IsPackageLevel"].Value = true;
}
else
{
Dts.Variables["User::IsPackageLevel"].Value = false;
}
Dts.TaskResult = (int)ScriptResults.Success;
}

From the SRC IsPackageLevel – get a line to connect an Exe SQL task

"SQL Update [DB Name]_Audit "

In connector – select the Evalution Operation as "Expression"
and Value as "Success" and Expression as "@IsPackageLevel || @Status!="Completed"".

Also select the Multiple Constraints with "OR" option.

And connect line to – "SQL Update [DB Name]_Audit " (Exe SQL Task)

In which, do as below:

--write the below script to update values in Audit
UPDATE [dbo].[Audit]
SET [Status] = 'Completed'
,[EndTime] = GETDATE()
Where AuditId= 0
GO

Go to Expression – select the "SqlStatementSource" option and write below query:

"UPDATE [dbo].[Audit]
SET [Status] = '"+ @[User::Status] +"'
,[EndTime] = GETDATE()
Where AuditId= "+ (DT_WSTR, 20) (@[User::AuditId]) +"
GO
"

Tuesday, June 26, 2012

Time Dimension Table Script

Script to create time dimension table with index


SET ANSI_PADDING OFF
BEGIN TRY
 DROP TABLE [DimTime]
END TRY
BEGIN CATCH
 --DO NOTHING
END CATCH


CREATE TABLE [dbo].[DimTime](
 [TimeSK] [int] IDENTITY(1,1) NOT NULL,
 [Time] [char](8) NOT NULL,
 [Hour] [char](2) NOT NULL,
 [MilitaryHour] [char](2) NOT NULL,
 [Minute] [char](2) NOT NULL,
 [Second] [char](2) NOT NULL,
 [AmPm] [char](2) NOT NULL,
 [StandardTime] [char](11) NULL,
 CONSTRAINT [PK_DimTime] PRIMARY KEY CLUSTERED 
 (
 [TimeSK] ASC
 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
 ) ON [PRIMARY]


GO
SET ANSI_PADDING OFF


PRINT CONVERT(VARCHAR,GETDATE(),113)--USED FOR CHECKING RUN TIME.


--Load time data for every second of a day
DECLARE @Time DATETIME


SET @TIME = CONVERT(VARCHAR,'12:00:00 AM',108)


TRUNCATE TABLE DimTime


WHILE @TIME <= '11:59:59 PM'
 BEGIN
 INSERT INTO dbo.DimTime([Time], [Hour], [MilitaryHour], [Minute], [Second], [AmPm])
 SELECT CONVERT(VARCHAR,@TIME,108) [Time]
 , CASE 
 WHEN DATEPART(HOUR,@Time) > 12 THEN DATEPART(HOUR,@Time) - 12
 ELSE DATEPART(HOUR,@Time) 
 END AS [Hour]
 , CAST(SUBSTRING(CONVERT(VARCHAR,@TIME,108),1,2) AS INT) [MilitaryHour]
 , DATEPART(MINUTE,@Time) [Minute]
 , DATEPART(SECOND,@Time) [Second]
 , CASE 
 WHEN DATEPART(HOUR,@Time) >= 12 THEN 'PM'
 ELSE 'AM'
 END AS [AmPm]


 SELECT @TIME = DATEADD(second,1,@Time)
 END


UPDATE DimTime
SET [HOUR] = '0' + [HOUR]
WHERE LEN([HOUR]) = 1


UPDATE DimTime
SET [MINUTE] = '0' + [MINUTE]
WHERE LEN([MINUTE]) = 1


UPDATE DimTime
SET [SECOND] = '0' + [SECOND]
WHERE LEN([SECOND]) = 1


UPDATE DimTime
SET [MilitaryHour] = '0' + [MilitaryHour]
WHERE LEN([MilitaryHour]) = 1


UPDATE DimTime
SET StandardTime = [Hour] + ':' + [Minute] + ':' + [Second] + ' ' + AmPm
WHERE StandardTime is null
AND HOUR <> '00'


UPDATE DimTime
SET StandardTime = '12' + ':' + [Minute] + ':' + [Second] + ' ' + AmPm
WHERE [HOUR] = '00'




--DimTime indexes
CREATE UNIQUE NONCLUSTERED INDEX [IDX_DimTime_Time] ON [dbo].[DimTime] 
(
[Time] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [IDX_DimTime_Hour] ON [dbo].[DimTime] 
(
[Hour] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [IDX_DimTime_MilitaryHour] ON [dbo].[DimTime] 
(
[MilitaryHour] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [IDX_DimTime_Minute] ON [dbo].[DimTime] 
(
[Minute] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [IDX_DimTime_Second] ON [dbo].[DimTime] 
(
[Second] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [IDX_DimTime_AmPm] ON [dbo].[DimTime] 
(
[AmPm] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [IDX_DimTime_StandardTime] ON [dbo].[DimTime] 
(
[StandardTime] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]


PRINT convert(varchar,getdate(),113)--USED FOR CHECKING RUN TIME.

Monday, June 25, 2012

Scenario (Updating the existing records and replacing with new entry and inserting new records)

Scenario: The details in the table is updated with IsActive, StartDate and EndDate columns to manage the History. The given script in this scenario is to reflect the below condition.


Condition: A table is already updated with records of product and representative details.
(1). When an existing product details updated in source, then the existing record should be udpated with EndDate  and '0' in IsActive column in destination. A new row should be inserted with the updated values with StartDate and '1' as IsActive. 
(2). When an existing employee details updated in source, then the existing record should be updated with respective changes in destination. No need to insert new row.
(3). When a new entry made in the source, then that should be inserted in the destination table.
(4). Delete the record in Destination when the record is deleted in source.


Below are the source tables:
ExamleTable1: work.dbo.Product
ExampleTable2: work.dbo.Employee
Now the below SQL tasks are used to perform the scripts for conditions.
Script to delete records in Destination those are deleted in source.

MERGE dbo.PractiseTable1 AS T
USING (SELECT [ProductId]
,[ProductName]
,[ProductType]
,[AvailableQty]
,[Price]
,[Location]
,[EmpName]
,[Age]
,[Designation]
,[CtNumber]
,1 AS [IsActive]
,GETDATE() AS StartDate
,NULL AS EndDate
,BINARY_CHECKSUM ([ProductId],[ProductName],[ProductType],[Price],[Location]) AS  HashKey
  FROM dbo.Employee S1
    JOIN dbo.Product S2
       ON s1.EmpId = s2.RepId) AS S
       ON s.productid = t.productid
 WHEN not matched BY source
  THEN DELETE;


Script to updating the existing records as Inactive with EndDate


MERGE dbo.PractiseTable1 AS T
USING (SELECT [ProductId]
,[ProductName]
,[ProductType]
,[AvailableQty]
,[Price]
,[Location]
,[EmpName]
,[Age]
,[Designation]
,[CtNumber]
,1 AS [IsActive]
,GETDATE() AS StartDate
,NULL AS EndDate
,BINARY_CHECKSUM ([ProductId],[ProductName],[ProductType],[Price],[Location]) AS HashKey
    FROM dbo.Employee S1
      JOIN dbo.Product S2
         ON s1.EmpId = s2.RepId) AS S
         ON s.productid = t.productid
   WHEN matched and s.hashkey <> t.hashkey
    THEN update
       SET t.IsActive = 0, T.Enddate = GETDATE();


Script to update records for changes in Employee table and to insert new records for changes in Product table


MERGE dbo.PractiseTable1 AS T
USING (SELECT [ProductId]
,[ProductName]
,[ProductType]
,[AvailableQty]
,[Price]
,[Location]
,[EmpName]
,[Age]
,[Designation]
,[CtNumber]
,1 AS [IsActive]
,GETDATE() AS StartDate
,NULL AS EndDate
,BINARY_CHECKSUM ([ProductId],[ProductName],[ProductType],[Price],[Location]) AS HashKey
FROM dbo.Employee S1
JOIN dbo.Product S2
ON s1.EmpId = s2.RepId) AS S
ON t.hashkey = s.hashkey
WHEN matched THEN UPDATE
SET t.[Productid] = s.[productid]
,t.[ProductType] = s.[ProductType]
,t.[AvailableQty] = s.[AvailableQty]
,t.[Price] = s.[Price]
,t.[Location] = s.[Location]
,t.[EmpName] = s.[EmpName]
,t.[Age] = s.[Age]
,t.[Designation] = s.[Designation]
,t.[CtNumber] = s.[CtNumber]
,t.[IsActive] = s.[IsActive]
,t.[StartDate] = s.[StartDate]
,t.[EndDate] = s.[EndDate]
,t.[HashKey] = s.[HashKey]
WHEN not matched
THEN INSERT  ([ProductId]
,[ProductName]
,[ProductType]
,[AvailableQty]
,[Price]
,[Location]
,[EmpName]
,[Age]
,[Designation]
,[CtNumber]
,[IsActive]
,[StartDate]
,[EndDate]
,[HashKey])
VALUES (s.[ProductId]
,s.[ProductName]
,s.[ProductType]
,s.[AvailableQty]
,s.[Price]
,s.[Location]
,s.[EmpName]
,s.[Age]
,s.[Designation]
,s.[CtNumber]
,s.[IsActive]
,s.[StartDate]
,s.[EndDate]
,s.[HashKey]);

Script to insert new records


MERGE dbo.PractiseTable1 AS T
USING (SELECT [ProductId] 
,[ProductName]
,[ProductType]
,[AvailableQty]
,[Price]
,[Location]
,[EmpName]
,[Age]
,[Designation]
,[CtNumber]
,1 AS [IsActive]
,GETDATE() AS StartDate
,NULL AS EndDate
,BINARY_CHECKSUM ([ProductId],[ProductName],[ProductType],[Price],[Location]) AS HashKey
FROM dbo.Employee S1
JOIN dbo.Product S2
ON s1.EmpId = s2.RepId) AS S
ON s.productid = t.productid
WHEN not matched
THEN INSERT  ([ProductId] 
,[ProductName]
,[ProductType]
,[AvailableQty]
,[Price]
,[Location]
,[EmpName]
,[Age]
,[Designation]
,[CtNumber]
,[IsActive]
,[StartDate]
,[EndDate]
,[HashKey])
VALUES (s.[ProductId] 
,s.[ProductName]
,s.[ProductType]
,s.[AvailableQty]
,s.[Price]
,s.[Location]
,s.[EmpName]
,s.[Age]
,s.[Designation]
,s.[CtNumber]
,s.[IsActive]
,s.[StartDate]
,s.[EndDate]
,s.[HashKey]);

Below is the result for the requirement.