 DECLARE @MaxOrganizationID AS int;
 SELECT @MaxOrganizationID = MAX(OrganizationID) FROM ODM2.ODM2Core.Organizations;
 --Add the analytical labs to the organizations table 
-INSERT INTO ODM2.ODM2Core.Organizations (OrganizationUniqueID, OrganizationUniqueIDTypeCV, OrganizationCode, OrganizationName, 
-	OrganizationDescription, OrganizationTypeCV, OrganizationLink, ParentOrganizationID)
-SELECT DISTINCT NULL AS OrganizationUniqueID, NULL AS OrganizationUniqueIDTypeCV, LabName AS OrganizationCode, LabName AS OrganizationName, 
-	LabOrganization AS OrganizationDescription, 'Analytical Laboratory' AS OrganizationTypeCV, NULL AS OrganizationLink, NULL AS ParentOrganizationID 
+INSERT INTO ODM2.ODM2Core.Organizations (OrganizationTypeCV, OrganizationCode, OrganizationName, OrganizationDescription, OrganizationLink, ParentOrganizationID)
+SELECT DISTINCT 'Analytical Laboratory' AS OrganizationTypeCV, LabName AS OrganizationCode, LabName AS OrganizationName, 
+	LabOrganization AS OrganizationDescription, NULL AS OrganizationLink, NULL AS ParentOrganizationID 
 FROM LittleBearRiverODM.dbo.LabMethods;
 --Create a temporary table that will make this easier
 SELECT DISTINCT lm.LabMethodID + @MaxMethodID + 1 AS MethodID, NULL AS MethodUniqueID, NULL AS MethodUniqueIDTypeCV, lm.LabMethodID + @MaxMethodID + 1 AS MethodCode, 

--2.  This uses "Research Institute" as the OrganizationTypeCV for now - this won't be true for all organizations stored in ODM 1.1 databases
--------------------------------------------------------------------------------------
SET IDENTITY_INSERT ODM2.ODM2Core.Organizations ON; 
INSERT INTO ODM2.ODM2Core.Organizations (OrganizationID, OrganizationUniqueID, OrganizationUniqueIDTypeCV, OrganizationCode, 
	OrganizationName, OrganizationDescription, OrganizationTypeCV, OrganizationLink, ParentOrganizationID)
SELECT SourceID AS OrganizationID, NULL AS OrganizationUniqueID, NULL AS OrganizationUniqueIDTypeCV, SourceID AS OrganizationCode, 
	Organization AS OrganizationName, CAST(SourceDescription AS VARCHAR(500)) AS OrganizationDescription, 'Research Institute' AS OrganizationTypeCV, 
	SourceLink AS OrganizationLink, NULL AS ParentOrganizationID 
FROM LittleBearRiverODM.dbo.Sources 
ORDER BY OrganizationID;

--------------------------------------------------------------------------------------
--Load the Methods from ODM 1.1 - can just move these straight across and use the same IDs
SET IDENTITY_INSERT ODM2.ODM2Core.Methods ON; 
INSERT INTO ODM2.ODM2Core.Methods (MethodID, MethodTypeCV, MethodCode, MethodName, MethodDescription, MethodLink, OrganizationID)
SELECT MethodID, 'Unknown' AS MethodTypeCV, MethodID AS MethodCode, MethodDescription AS MethodName, 
	MethodDescription, MethodLink, NULL AS OrganizationID  
FROM LittleBearRiverODM.dbo.Methods 
ORDER BY MethodID;
SET IDENTITY_INSERT ODM2.ODM2Core.Methods OFF;
