SET NOCOUNT ON
DECLARE @GroupName varchar(30)
DECLARE @SortNumber int
DECLARE @GroupCode varchar(3)

DECLARE @CountryName varchar(30)
DECLARE @CountryCode varchar(3)
DECLARE @CurrencyCode varchar(3)
DECLARE @CurrencyName varchar(30)

DECLARE @CountryGroupNumber int

DECLARE @OtherEurope int
DECLARE @OtherAfrica int
DECLARE @OtherAmerica int
DECLARE @OtherAsia int
DECLARE @OtherOceanic int
DECLARE @OtherWorld int
DECLARE @Denmark int
DECLARE @Finland int

DECLARE @TheCountryCode varchar(3)

SELECT @TheCountryCode = CountryCode 
FROM Countries WITH (NOLOCK) 
WHERE CountryNumber = (SELECT KeyValue FROM HotelSetup WITH (NOLOCK) WHERE SearchKey = 'COUNTRYCODE')

IF @TheCountryCode = 'N'
BEGIN
  CREATE TABLE #TempGroups (
    CountryName VARCHAR(30) NOT NULL,
    GroupSortNumber INT NOT NULL,
    CountryCode VARCHAR(3) NOT NULL
  )

  INSERT INTO #TempGroups VALUES ('Norge',1,'N')
  INSERT INTO #TempGroups VALUES ('Sverige',2,'S')
  INSERT INTO #TempGroups VALUES ('Danmark',3,'DK')
  INSERT INTO #TempGroups VALUES ('Finland',4,'FIN')
  INSERT INTO #TempGroups VALUES ('Island',5,'IS')
  INSERT INTO #TempGroups VALUES ('Storbritannia',6,'GB')
  INSERT INTO #TempGroups VALUES ('Nederland',7,'NL')
  INSERT INTO #TempGroups VALUES ('Tyskland',8,'D')
  INSERT INTO #TempGroups VALUES ('Frankrike',9,'F')
  INSERT INTO #TempGroups VALUES ('Spania',10,'E')
  INSERT INTO #TempGroups VALUES ('Sveits',11,'CH')
  INSERT INTO #TempGroups VALUES ('Liechtenstein',12,'LI')
  INSERT INTO #TempGroups VALUES ('Italia',13,'I')
  INSERT INTO #TempGroups VALUES ('Østerrike',14,'A')
  INSERT INTO #TempGroups VALUES ('Belgia',15,'B')
  INSERT INTO #TempGroups VALUES ('Portugal',16,'P')
  INSERT INTO #TempGroups VALUES ('Hellas',17,'GR')
  INSERT INTO #TempGroups VALUES ('Irland',18,'IRL')
  INSERT INTO #TempGroups VALUES ('Luxembourg',19,'L')
  INSERT INTO #TempGroups VALUES ('Tyrkia',20,'TR')
  INSERT INTO #TempGroups VALUES ('Polen',21,'PL')
  INSERT INTO #TempGroups VALUES ('Tsjekkia',22,'CZ')
  INSERT INTO #TempGroups VALUES ('Slovakia',23,'SK')
  INSERT INTO #TempGroups VALUES ('Ungarn',24,'H')
  INSERT INTO #TempGroups VALUES ('Estland',25,'EE')
  INSERT INTO #TempGroups VALUES ('Latvia',26,'LV')
  INSERT INTO #TempGroups VALUES ('Litauen',27,'LT')
  INSERT INTO #TempGroups VALUES ('Kypros',28,'CY')
  INSERT INTO #TempGroups VALUES ('Malta',29,'MT')
  INSERT INTO #TempGroups VALUES ('Slovenia',30,'SI')
  INSERT INTO #TempGroups VALUES ('Ukraina',31,'UA')
  INSERT INTO #TempGroups VALUES ('Russland',32,'RU')
  INSERT INTO #TempGroups VALUES ('Romania',33,'RO')
  INSERT INTO #TempGroups VALUES ('Bulgaria',34,'BG')
  INSERT INTO #TempGroups VALUES ('Kroatia',35,'HR')  
  INSERT INTO #TempGroups VALUES ('Andre europeiske land',36,'OE')
  INSERT INTO #TempGroups VALUES ('USA',37,'USA')
  INSERT INTO #TempGroups VALUES ('Canada',38,'CA')
  INSERT INTO #TempGroups VALUES ('Mexico',39,'MX')
  INSERT INTO #TempGroups VALUES ('Brasil',40,'BR')
  INSERT INTO #TempGroups VALUES ('Latin-Amerika ellers',41,'OA')
  INSERT INTO #TempGroups VALUES ('Australia',42,'AU')
  INSERT INTO #TempGroups VALUES ('Oseania ellers',43,'OOL')
  INSERT INTO #TempGroups VALUES ('Japan',44,'JP')
  INSERT INTO #TempGroups VALUES ('Kina',45,'CN')
  INSERT INTO #TempGroups VALUES ('Sør-Korea',46,'KR')
  INSERT INTO #TempGroups VALUES ('Andre asiatiske lande',47,'OAL')
  INSERT INTO #TempGroups VALUES ('Sør-Afrika',48,'ZA')
  INSERT INTO #TempGroups VALUES ('Andre afrikanske land',49,'OA1')

	DECLARE db_cur CURSOR FOR
	  SELECT * FROM #TempGroups WITH (nolock)
	OPEN db_cur 
	   
	FETCH NEXT FROM db_cur INTO @GroupName, @SortNumber, @GroupCode
	    
	WHILE @@fetch_status = 0 
	BEGIN
	  -- Der er nogle lande hvor GroupName skal renames
	  IF @SortNumber = 6   -- Storbritanien 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Storbritannia' OR GroupName LIKE '%/ Nord irland%' OR GroupName LIKE '%/ Nordirland%' OR GroupName LIKE '%Storbritanien%'
	  IF @SortNumber = 7   -- Holland 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Holland' OR GroupName = 'Nederland'
	  IF @SortNumber = 9   -- Frankrig 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Frankrig' OR GroupName = 'Frankrike'
	  IF @SortNumber = 10   -- Spanien 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Spanien' OR GroupName = 'Spania'
	  IF @SortNumber = 11   -- Schweiz 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Schweiz' OR GroupName = 'Sveits'
	  IF @SortNumber = 13   -- Italien
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Italien' OR GroupName = 'Italia'
	  IF @SortNumber = 14   -- Østrig
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Østerrike' OR GroupName = 'Austria' OR GroupName = 'Østrig'
	  IF @SortNumber = 15   -- Belgien 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Belgien' OR GroupName = 'Belgia'
	  IF @SortNumber = 17   -- Grækenland 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Grækenland' OR GroupName = 'Grµkenland'
	  IF @SortNumber = 19   -- Luxemborg 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Luxemborg' OR GroupName = 'Luxembourg'
	  IF @SortNumber = 20   -- Tyrkiet 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Tyrkiet' OR GroupName = 'Tyrkia'
	  IF @SortNumber = 22   -- Tjekkiet
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Tjekkiet' OR GroupName = 'Tsjekkia'
	  IF @SortNumber = 23   -- Slovakiet 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Slovakiet' OR GroupName = 'Slovakia'
	  IF @SortNumber = 26   -- Letland 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Letland' OR GroupName = 'Latvia'
	  IF @SortNumber = 28   -- Cypern 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Cypern' OR GroupName = 'Kypros'
	  IF @SortNumber = 30   -- Slovenien 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Slovenien' OR GroupName = 'Slovenia'
	  IF @SortNumber = 31   -- Ukraine
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Ukraine' OR GroupName = 'Ukraina'
	  IF @SortNumber = 32   -- Rusland 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Rusland' OR GroupName = 'Russland'
	  IF @SortNumber = 33   -- Romænien 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Romania' OR GroupName = 'Rumænien'
	  IF @SortNumber = 34   -- Bulgarien
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Bulgaria' OR GroupName = 'Bulgarien'
	  IF @SortNumber = 36   -- Andre europæiske lande 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode WHERE GroupName LIKE '%Europa i %vrigt%' OR GroupCode = 'EO' OR GroupName LIKE '%Andre europæiske lande%' OR GroupName = 'Europa ellers'
	  IF @SortNumber = 40   -- Brasilien 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode WHERE GroupName = 'Brasilien' OR GroupName = 'Brasil'
	  IF @SortNumber = 41   -- Andre amerikanske lande 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode WHERE GroupName LIKE '%Amerika i %vrigt' OR GroupCode = 'AO' OR GroupName LIKE '%Andre afrikanske lande%' OR GroupName = 'Amerika ellers'
	  IF @SortNumber = 42   -- Australien 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode WHERE GroupName = 'Australien' OR GroupName = 'Australia'
	  IF @SortNumber = 43   -- Andre oceaniske lande 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode WHERE GroupName LIKE '%Andre oceaniske lande%' 
	  IF @SortNumber = 45   -- Folkerepublikken Kina
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode WHERE GroupName LIKE '%Folkerepublikken Kina%' OR GroupName = 'Kina'
	  IF @SortNumber = 46   -- Sydkorea
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Sydkorea' OR GroupName = 'Sør-Korea'
	  IF @SortNumber = 47   -- Andre asiatiske lande 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode WHERE GroupName LIKE '%Syd%stasian i %vrigt%' OR GroupName LIKE '%Syd%stasien i %vrigt%' OR GroupCode = 'SO' OR GroupName = 'Andre land'
	  IF @SortNumber = 48   -- Sydafrika 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Sydafrika' Or GroupName = 'Sør-Afrika'
	  IF @SortNumber = 49   -- Andre afrikanske lande 
	    UPDATE CountryGroups SET GroupName = @GroupName, GroupSortNumber = @SortNumber, GroupCode = @GroupCode WHERE GroupName LIKE '%Andre amerikanske lande%' OR GroupName ='Afrika' OR GroupName = 'Øvrige lande'

    IF @@RowCount > 0
    BEGIN
	    PRINT 'Rename: ' + @GroupName
	    FETCH NEXT FROM db_cur INTO @GroupName, @SortNumber, @GroupCode
	    CONTINUE
    END
	  IF NOT EXISTS (SELECT GroupName FROM CountryGroups WITH (NOLOCK) WHERE GroupName = @GroupName) 
	  BEGIN
	    PRINT 'Insert: ' + @GroupName
	    INSERT INTO CountryGroups (GroupName, GroupSortNumber, GroupCode) VALUES (@GroupName,@SortNumber,@GroupCode)
	  END
	  ELSE
	  BEGIN
	    UPDATE CountryGroups SET GroupSortNumber = @SortNumber, GroupCode = @GroupCode WHERE GroupName = @GroupName
	    PRINT 'Update: ' + @GroupName
	  END
	  
    FETCH NEXT FROM db_cur INTO @GroupName, @SortNumber, @GroupCode
  END
  
  CREATE TABLE #TempCountries (CountryName     varchar(30) NOT NULL,
                               CountryCode     varchar(3)  NOT NULL,
                               CurrencyCode    varchar(3)  NOT NULL,
                               CurrencyName    varchar(30) NOT NULL)
  
	INSERT INTO #TempCountries VALUES ('Romania','RO','DKK','Danske kroner')
	INSERT INTO #TempCountries VALUES ('Bulgaria','BG','BEF','Franc')
	INSERT INTO #TempCountries VALUES ('Kroatia','HR','CYP','Pound')

	DECLARE db_cur1 CURSOR FOR
	  SELECT * FROM #TempCountries WITH (nolock)
	OPEN db_cur1 
	 
	FETCH NEXT FROM db_cur1 INTO @CountryName, @CountryCode, @CurrencyCode, @CurrencyName
	  
	WHILE @@fetch_status = 0 
	BEGIN
	  IF NOT EXISTS (SELECT CountryName FROM Countries WITH (NOLOCK) WHERE CountryName = @CountryName) 
	  BEGIN
--	    PRINT 'Insert country: ' + @CountryName
	    SELECT @CountryGroupNumber = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupCode = @CountryCode
	    INSERT INTO Countries (CountryName, CountryCode, MarkAsDeleted, CountryGroupNumber, CurrencyCode, CurrencyName, SortNumber) VALUES (@CountryName,@CountryCode,0,@CountryGroupNumber,@CurrencyCode,@CurrencyName, 999)
	  END
	  ELSE
	  BEGIN 
--    PRINT 'Update country: ' + @CountryName
	    SELECT @CountryGroupNumber = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupCode = @CountryCode
	    UPDATE Countries SET CountryGroupNumber = @CountryGroupNumber, MarkAsDeleted = 0, CurrencyCode = @CurrencyCode, CurrencyName = @CurrencyName WHERE CountryName = @CountryName   
	  END
	
	  FETCH NEXT FROM db_cur1 INTO @CountryName, @CountryCode, @CurrencyCode, @CurrencyName
	END --end Danish/Norwegian/Grønland countries

	--Hent Hvilket nr de enkelte grupper har fået.
	SELECT @OtherEurope = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupSortNumber = 36
	SELECT @OtherAfrica = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupSortNumber = 49
	SELECT @OtherAmerica = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupSortNumber = 41
	SELECT @OtherAsia = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupSortNumber = 47
	SELECT @OtherOceanic = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupSortNumber = 43

  --hent liste over alle andre lande og del op i korrekte grupper
  DECLARE db_cur2 CURSOR FOR
    SELECT CountryName, CountryGroupNumber FROM Countries WITH (nolock)
  OPEN db_cur2 
 
  FETCH NEXT FROM db_cur2 INTO @CountryName, @CountryGroupNumber
  
  WHILE @@fetch_status = 0 
  BEGIN
    IF @CountryName = 'Algeria' or @CountryName = 'Angola' or @CountryName = 'Benin' or @CountryName = 'Botswana' or @CountryName = 'Burkina Faso' or 
      @CountryName = 'Burundi' or @CountryName = 'Cameroon' or @CountryName = 'Cape Verde' or @CountryName = 'Central African Republic' or @CountryName = 'Chad' or 
      @CountryName = 'Comoros' or @CountryName = 'Cote dIvoire' or @CountryName = 'Egypt' or @CountryName = 'Equatorial Guinea' or @CountryName = 'Eritrea' or 
      @CountryName = 'Ethiopia' or @CountryName = 'Gabon' or @CountryName = 'Gambia' or @CountryName = 'Ghana' or @CountryName = 'Guinea-Bissau' or 
      @CountryName = 'Guinea' or @CountryName = 'Kenya' or @CountryName = 'Liberia' or @CountryName = 'Libya' or @CountryName = 'Madagascar' or @CountryName = 'Malawi' or 
      @CountryName = 'Mali' or @CountryName = 'Mauritania' or @CountryName = 'Mauritius' or @CountryName = 'Morocco' or @CountryName = 'Mozambique' or 
      @CountryName = 'Namibia' or @CountryName = 'Nigeria' or @CountryName = 'Niger' or @CountryName = 'Republic of the Congo' or @CountryName = 'Rwanda' or 
      @CountryName = 'Sao Tome and Principe' or @CountryName = 'Senegal' or @CountryName = 'Seychelles' or @CountryName = 'Sierra Leone' or @CountryName = 'Somalia' or 
      @CountryName = 'Sudan' or @CountryName = 'Swaziland' or @CountryName = 'Tanzania' or @CountryName = 'Togo' or @CountryName = 'Tunisia' or 
      @CountryName = 'Uganda' or @CountryName = 'Zambia' or @CountryName = 'Zimbabwe' or @CountryName = 'Congo' or @CountryName = 'Tunesia' 
    BEGIN
      -- Africa
      UPDATE Countries SET CountryGroupNumber = @OtherAfrica WHERE CountryName = @CountryName 
    END

    IF @CountryName = 'Armenia' OR @CountryName = 'ORAzerbaijan' OR @CountryName = 'Bangladesh' OR @CountryName = 'Brunei' OR @CountryName = 'Cambodia' OR
      @CountryName = 'Georgia' OR @CountryName = 'Hong Kong' OR @CountryName = 'India' OR @CountryName = 'Indonesia' OR @CountryName = 'Iran' OR
      @CountryName = 'Iraq' OR @CountryName = 'Israel' OR @CountryName = 'Jordan' OR @CountryName = 'Kazakhstan' OR @CountryName = 'Kuwait' OR
      @CountryName = 'Laos' OR @CountryName = 'Lebanon' OR @CountryName = 'Macao' OR @CountryName = 'Malaysia' OR @CountryName = 'Maldives' OR @CountryName = 'Mongolia' OR
      @CountryName = 'Myanmar' OR @CountryName = 'Nepal' OR @CountryName = 'North Korea' OR @CountryName = 'Oman' OR @CountryName = 'Pakistan' OR
      @CountryName = 'Philippines' OR @CountryName = 'Qatar' OR @CountryName = 'Saudi Arabia' OR @CountryName = 'Singapore' OR @CountryName = 'Sri Lanka' OR
      @CountryName = 'Syria' OR @CountryName = 'Taiwan' OR @CountryName = 'Tajikistan' OR @CountryName = 'Oman' OR @CountryName = 'Thailand' OR
      @CountryName = 'United Arab Emirates' OR @CountryName = 'Vietnam' OR @CountryName = 'Yemen' OR @CountryName = 'Sri Lanca'
    BEGIN
      -- Asia
      UPDATE Countries SET CountryGroupNumber = @OtherAsia WHERE CountryName = @CountryName 
    END

    IF @CountryName = 'Federated States of Micronesia' OR @CountryName = 'Fiji' OR @CountryName = 'Kiribati' OR @CountryName = 'Marshall Islands' OR
      @CountryName = 'Nauru' OR @CountryName = 'New Zealand' OR @CountryName = 'Palau' OR @CountryName = 'Papua New Guinea' OR @CountryName = 'Samoa' OR
      @CountryName = 'Solomon Islands' OR @CountryName = 'Tonga' OR @CountryName = 'Tuvalu' OR @CountryName = 'Vanuatu'
    BEGIN
      -- Oceanic
      UPDATE Countries SET CountryGroupNumber = @OtherOceanic WHERE CountryName = @CountryName 
    END

    IF @CountryName = 'Albania' or @CountryName = 'Andorra' or @CountryName = 'Belarus' or @CountryName = 'Bosnia and Herzegovina' or
      @CountryName = 'Liechtenstein' or @CountryName = 'Macedonia' or @CountryName = 'Moldova' or
      @CountryName = 'San Marino' or @CountryName = 'Vatican City' or @CountryName = 'Yugoslavia' OR @CountryName = 'Euro' or @CountryName = 'Vatican'
    BEGIN
      -- Europe 
      UPDATE Countries SET CountryGroupNumber = @OtherEurope WHERE CountryName = @CountryName 
    END

    IF @CountryName = 'Belize' OR @CountryName = 'Costa Rica' OR @CountryName = 'Cuba' OR @CountryName = 'Dominican Republic' OR @CountryName = 'El Salvador' OR
      @CountryName = 'Guatemala' OR @CountryName = 'Haiti' OR @CountryName = 'Honduras' OR @CountryName = 'Jamaica' OR @CountryName = 'Mexico' OR
      @CountryName = 'Nicaragua' OR @CountryName = 'Panama' OR @CountryName = 'Argentina' OR @CountryName = 'Bolivia' OR @CountryName = 'Chile' OR
      @CountryName = 'Colombia' OR @CountryName = 'Ecuador' OR @CountryName = 'French Guiana' OR @CountryName = 'Guyana' OR @CountryName = 'Paraguay' OR
      @CountryName = 'Peru' OR @CountryName = 'Suriname' OR @CountryName = 'Uruguay' OR @CountryName = 'Venezuela' OR @CountryName = 'Equador'
    BEGIN
      --America
      UPDATE Countries SET CountryGroupNumber = @OtherAmerica WHERE CountryName = @CountryName 
    END

    FETCH NEXT FROM db_cur2 INTO @CountryName, @CountryGroupNumber
  END

  DEALLOCATE db_cur
  DEALLOCATE db_cur1
  DEALLOCATE db_cur2

  DROP TABLE #TempGroups
  DROP TABLE #TempCountries

  -- Some countryGroups should be deleted
  --Færøerne
  UPDATE Countries SET CountryGroupNumber = @OtherEurope 
  WHERE CountryGroupNumber IN (SELECT GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupCode = 'FO')
  DELETE CountryGroups WHERE GroupCode = 'FO'
  --Grønland
  UPDATE Countries SET CountryGroupNumber = @OtherEurope 
  WHERE CountryGroupNumber IN (SELECT GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupCode = 'GL')
  DELETE CountryGroups WHERE GroupCode = 'GL'
END