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 ('Danmark',1,'DK')
  INSERT INTO #TempGroups VALUES ('Finland',2,'FI')
  INSERT INTO #TempGroups VALUES ('Island',3,'IS')
  INSERT INTO #TempGroups VALUES ('Norge',4,'NO')
  INSERT INTO #TempGroups VALUES ('Sverige',5,'SE')

  INSERT INTO #TempGroups VALUES ('Albania',6,'AL')
  INSERT INTO #TempGroups VALUES ('Andorra',7,'AD')
  INSERT INTO #TempGroups VALUES ('Belgia',8,'BE')
  INSERT INTO #TempGroups VALUES ('Bosnia and Herzegovina',9,'BA')
  INSERT INTO #TempGroups VALUES ('Bulgaria',10,'BG')
  INSERT INTO #TempGroups VALUES ('Estland',11,'EE')
  INSERT INTO #TempGroups VALUES ('Frankrike',12,'F')
  INSERT INTO #TempGroups VALUES ('Hellas',13,'GR')
  INSERT INTO #TempGroups VALUES ('Belarus',14,'BY')
  INSERT INTO #TempGroups VALUES ('Irland',15,'IE')
  INSERT INTO #TempGroups VALUES ('Italia',16,'IT')
  INSERT INTO #TempGroups VALUES ('Kosovo',17,'KO')
  INSERT INTO #TempGroups VALUES ('Kroatia',18,'HR')
  INSERT INTO #TempGroups VALUES ('Kypros',19,'CY')
  INSERT INTO #TempGroups VALUES ('Latvia',20,'LV')
  INSERT INTO #TempGroups VALUES ('Liechtenstein',21,'LI')
  INSERT INTO #TempGroups VALUES ('Litauen',22,'LT')
  INSERT INTO #TempGroups VALUES ('Luxembourg',23,'LU')
  INSERT INTO #TempGroups VALUES ('Makedonia',24,'MK')
  INSERT INTO #TempGroups VALUES ('Malta',25,'MT')
  INSERT INTO #TempGroups VALUES ('Moldova',26,'MD')
  INSERT INTO #TempGroups VALUES ('Monaco',27,'MC')
  INSERT INTO #TempGroups VALUES ('Montenegro',28,'ME')
  INSERT INTO #TempGroups VALUES ('Nederlands',29,'NL')
  INSERT INTO #TempGroups VALUES ('Polen',30,'PL')
  INSERT INTO #TempGroups VALUES ('Portugal',31,'PT')
  INSERT INTO #TempGroups VALUES ('Romania',32,'RO')
  INSERT INTO #TempGroups VALUES ('Russland',33,'RU')
  INSERT INTO #TempGroups VALUES ('San Marino',34,'SM')
  INSERT INTO #TempGroups VALUES ('Serbia',35,'RS')
  INSERT INTO #TempGroups VALUES ('Slovakia',36,'SK')
  INSERT INTO #TempGroups VALUES ('Slovenia',37,'SI')
  INSERT INTO #TempGroups VALUES ('Spania',38,'ES')
  INSERT INTO #TempGroups VALUES ('Storbritannia',39,'GB')
  INSERT INTO #TempGroups VALUES ('Sveits',40,'CH')
  INSERT INTO #TempGroups VALUES ('Tsjekkia',41,'CZ')
  INSERT INTO #TempGroups VALUES ('Turkey',42,'TR')
  INSERT INTO #TempGroups VALUES ('Tyskland',43,'DE')
  INSERT INTO #TempGroups VALUES ('Ukraina',44,'UA')
  INSERT INTO #TempGroups VALUES ('Ungarn',45,'HU')
  INSERT INTO #TempGroups VALUES ('Vertikanstaten',46,'VA')
  INSERT INTO #TempGroups VALUES ('Østerrike',47,'AT')

  INSERT INTO #TempGroups VALUES ('Arabiske Emirater',48,'AE')
  INSERT INTO #TempGroups VALUES ('India',49,'IN')
  INSERT INTO #TempGroups VALUES ('Indonesia',50,'ID')
  INSERT INTO #TempGroups VALUES ('Japan',51,'JP')
  INSERT INTO #TempGroups VALUES ('Kina',52,'CN')
  INSERT INTO #TempGroups VALUES ('Malaysia',53,'MY')
  INSERT INTO #TempGroups VALUES ('Qatar',54,'QA')
  INSERT INTO #TempGroups VALUES ('Singapore',55,'SG')
  INSERT INTO #TempGroups VALUES ('Sør-Korea',56,'KR')
  INSERT INTO #TempGroups VALUES ('Taiwan',57,'TW')
  INSERT INTO #TempGroups VALUES ('Thailand',58,'TH')
  INSERT INTO #TempGroups VALUES ('Andre asiatiske lande',59,'OAL')

  INSERT INTO #TempGroups VALUES ('Brazil',60,'BR')
  INSERT INTO #TempGroups VALUES ('Canada',61,'CA')
  INSERT INTO #TempGroups VALUES ('Mexico',62,'MX')
  INSERT INTO #TempGroups VALUES ('USA',63,'US')
  INSERT INTO #TempGroups VALUES ('Latin-Amerika ellers',64,'OA')

  INSERT INTO #TempGroups VALUES ('Australia',65,'AU')
  INSERT INTO #TempGroups VALUES ('Oseania ellers',66,'OOL')

  INSERT INTO #TempGroups VALUES ('Sør-Afrika',67,'ZA')
  INSERT INTO #TempGroups VALUES ('Andre afrikanske land',68,'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
    IF @SortNumber = 64   -- Andre amerikanske lande 
 	    UPDATE CountryGroups SET GroupName = @GroupName, SortNumber2 = @SortNumber, GroupCode = @GroupCode 
      WHERE GroupName LIKE '%Amerika i %vrigt' OR GroupCode = 'AO' OR GroupName LIKE '%Andre afrikanske lande%' OR GroupName = 'Amerika ellers' OR GroupName = 'Andre amerikanske land'
	  IF @SortNumber = 66   -- Andre oceaniske lande 
	    UPDATE CountryGroups SET GroupName = @GroupName, SortNumber2 = @SortNumber, GroupCode = @GroupCode WHERE GroupName LIKE '%Andre oceaniske lande%' OR GroupName = 'Andre oceaniske land'
	  IF @SortNumber = 56   -- Sydkorea
	    UPDATE CountryGroups SET GroupName = @GroupName, SortNumber2 = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Sydkorea' OR GroupName = 'Sør-Korea' OR GroupName = 'Sørkorea'
	  IF @SortNumber = 59   -- Andre asiatiske lande 
	    UPDATE CountryGroups SET GroupName = @GroupName, SortNumber2 = @SortNumber, GroupCode = @GroupCode 
      WHERE GroupName LIKE '%Syd%stasian i %vrigt%' OR GroupName LIKE '%Syd%stasien i %vrigt%' OR GroupCode = 'SO' OR GroupName = 'Andre land' OR GroupName = 'Andre asiatiske land'
	  IF @SortNumber = 67   -- Sydafrika 
	    UPDATE CountryGroups SET GroupName = @GroupName, SortNumber2 = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Sydafrika' Or GroupName = 'Sør-Afrika' OR GroupName = 'Sørafrika'
	  IF @SortNumber = 60   -- Brasil
	    UPDATE CountryGroups SET GroupName = @GroupName, SortNumber2 = @SortNumber, GroupCode = @GroupCode  WHERE GroupName = 'Brazil' Or GroupName = 'Brasil'

    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, SortNumber2, GroupCode) VALUES (@GroupName,@SortNumber,@GroupCode)
	  END
	  ELSE
	  BEGIN
	    UPDATE CountryGroups SET SortNumber2 = @SortNumber, GroupCode = @GroupCode WHERE GroupName = @GroupName
	    PRINT 'Update: ' + @GroupName
	  END
	  
    FETCH NEXT FROM db_cur INTO @GroupName, @SortNumber, @GroupCode
  END

  UPDATE CountryGroups 
  SET SortNumber2 = NULL 
  WHERE GroupName LIKE '%Europa i %vrigt%' 
  OR GroupCode = 'EO' 
  OR GroupName LIKE '%Andre europæiske lande%' 
  OR GroupName = 'Europa ellers' 
  OR GroupName = 'Andre europeiske land'

  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 ('Denmark','DK','DKK','Krone')
  INSERT INTO #TempCountries VALUES ('Finland','FI','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Iceland','IS','ISK','Krona')
  INSERT INTO #TempCountries VALUES ('Norway','NO','NOK','Krone')
  INSERT INTO #TempCountries VALUES ('Sweden','SE','SEK','Krona')

  INSERT INTO #TempCountries VALUES ('Albania','AL','ALL','Lek')
  INSERT INTO #TempCountries VALUES ('Andorra','AD','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Belgium','BE','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Bosnia and Herzegovina','BA','BAM','Mark')
  INSERT INTO #TempCountries VALUES ('Bulgaria','BG','BGN','Lev')
  INSERT INTO #TempCountries VALUES ('Estonia','EE','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('France','F','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Greece','GR','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Belarus','BY','BYN','Ruble')
  INSERT INTO #TempCountries VALUES ('Ireland','IE','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Italy','IT','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Kosovo','KO','ALL','Lek')
  INSERT INTO #TempCountries VALUES ('Kroatia','HR','HRK','Kuna')
  INSERT INTO #TempCountries VALUES ('Cyprus','CY','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Latvia','LV','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Liechtenstein','LI','CHF','Franc')
  INSERT INTO #TempCountries VALUES ('Lithuania','LT','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Luxembourg','LU','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Makedonia','MK','MKD','Denar')
  INSERT INTO #TempCountries VALUES ('Malta','MT','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Moldova','MD','MDL','Leu')
  INSERT INTO #TempCountries VALUES ('Monaco','MC','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Montenegro','ME','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Netherlands','NL','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Poland','PL','PLN','Zloty')
  INSERT INTO #TempCountries VALUES ('Portugal','PT','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Romania','RO','RON','Leu')
  INSERT INTO #TempCountries VALUES ('Russia','RU','RUB','Ruble')
  INSERT INTO #TempCountries VALUES ('San Marino','SM','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Serbia','RS','RSD','Dinar')
  INSERT INTO #TempCountries VALUES ('Slovakia','SK','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Slovenia','SI','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Spain','ES','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('United Kingdom','GB','GBP','Pund')
  INSERT INTO #TempCountries VALUES ('Switzerland','CH','CHF','Franc')
  INSERT INTO #TempCountries VALUES ('Czech Republic','CZ','CZK','Koruna')
  INSERT INTO #TempCountries VALUES ('Turkey','TR','TRY','Lira')
  INSERT INTO #TempCountries VALUES ('Germany','DE','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Ukraine','UA','UAH','Hryvnia')
  INSERT INTO #TempCountries VALUES ('Hungary','HU','HUF','Forint')
  INSERT INTO #TempCountries VALUES ('Vertikanstaten','VA','EUR','EURO')
  INSERT INTO #TempCountries VALUES ('Austria','AT','EUR','EURO')

  INSERT INTO #TempCountries VALUES ('Arabiske Emirater','AE','AED','Dirham')
  INSERT INTO #TempCountries VALUES ('India','IN','INR','Rupee')
  INSERT INTO #TempCountries VALUES ('Indonesia','ID','IDR','Rupiah')
  INSERT INTO #TempCountries VALUES ('Japan','JP','JPY','Yen')
  INSERT INTO #TempCountries VALUES ('China','CN','CNY','Renminbi')
  INSERT INTO #TempCountries VALUES ('Malaysia','MY','MYR','Ringgit')
  INSERT INTO #TempCountries VALUES ('Qatar','QA','QAR','Rial')
  INSERT INTO #TempCountries VALUES ('Singapore','SG','SGD','Dollar')
  INSERT INTO #TempCountries VALUES ('South Korea','KR','KRW','Won')
  INSERT INTO #TempCountries VALUES ('Taiwan','TW','TWD','Dollar')
  INSERT INTO #TempCountries VALUES ('Thailand','TH','THB','Bath')
  INSERT INTO #TempCountries VALUES ('Andre asiatiske lande','OAL','','')

  INSERT INTO #TempCountries VALUES ('Brazil','BR','BRL','Real')
  INSERT INTO #TempCountries VALUES ('Canada','CA','CAD','Dollar')
  INSERT INTO #TempCountries VALUES ('Mexico','MX','MXN','Peso')
  INSERT INTO #TempCountries VALUES ('USA','US','USD','Dollar')
  INSERT INTO #TempCountries VALUES ('Latin-Amerika ellers','OA','','')

  INSERT INTO #TempCountries VALUES ('Australia','AU','AUD','Dollar')
  INSERT INTO #TempCountries VALUES ('Oseania ellers','OOL','','')

  INSERT INTO #TempCountries VALUES ('South Africa','ZA','ZAR','Rand')
  INSERT INTO #TempCountries VALUES ('Andre afrikanske land','OA1','','')

	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, CountryGroupNumber2, CurrencyCode, CurrencyName, SortNumber) VALUES (@CountryName,@CountryCode,0,@CountryGroupNumber,@CountryGroupNumber,@CurrencyCode,@CurrencyName, 999)
	  END
	  ELSE
	  BEGIN 
--    PRINT 'Update country: ' + @CountryName
	    SELECT @CountryGroupNumber = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupCode = @CountryCode
	    UPDATE Countries SET CountryGroupNumber2 = @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 SortNumber2 = 4 -- Actually Norway. Other europe does not exists any longer
	SELECT @OtherAfrica = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE SortNumber2 = 68
	SELECT @OtherAmerica = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE SortNumber2 = 64
	SELECT @OtherAsia = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE SortNumber2 = 59
	SELECT @OtherOceanic = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE SortNumber2 = 66

  --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 = '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 = '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 = 'Saudi Arabia' OR @CountryName = 'Sri Lanka' OR
      @CountryName = 'Syria' OR @CountryName = 'Tajikistan' OR @CountryName = 'Oman' 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 = 'Yugoslavia' OR @CountryName = 'Euro'
    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 = '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

  -- Other europe not used anymore
  UPDATE Countries SET CountryGroupNumber2 = NULL WHERE CountryName IN ('Other Europe', 'Other Transatlantic', 'Other World')
  
  DEALLOCATE db_cur
  DEALLOCATE db_cur1
  DEALLOCATE db_cur2

  DROP TABLE #TempGroups
  DROP TABLE #TempCountries
END