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

CREATE TABLE #TempGroups (CountryName     VarChar(30) NOT NULL,
                          GroupSortNumber Int         NOT NULL,
                          CountryCode     varchar(3)  NOT NULL)

DECLARE @TheCountryCode varchar(3)

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

IF @TheCountryCode = 'DK' OR @TheCountryCode = 'IRL' OR @TheCountryCode = 'IR'
BEGIN
  INSERT INTO #TempGroups VALUES ('Danmark',1,'DK')
  INSERT INTO #TempGroups VALUES ('Færøerne',2,'FO')
  INSERT INTO #TempGroups VALUES ('Grønland',3,'GL')
  INSERT INTO #TempGroups VALUES ('Belgien',4,'B')
  INSERT INTO #TempGroups VALUES ('Bulgarien',5,'BG')
  INSERT INTO #TempGroups VALUES ('Cypern',6,'CY')
  INSERT INTO #TempGroups VALUES ('Estland',7,'EE')
  INSERT INTO #TempGroups VALUES ('Finland',8,'FIN')
  INSERT INTO #TempGroups VALUES ('Frankrig',9,'F')
  INSERT INTO #TempGroups VALUES ('Grækenland',10,'GR')
  INSERT INTO #TempGroups VALUES ('Holland',11,'NL')
  INSERT INTO #TempGroups VALUES ('Irland',12,'IRL')
  INSERT INTO #TempGroups VALUES ('Island',13,'IS')
  INSERT INTO #TempGroups VALUES ('Italien',14,'I')
  INSERT INTO #TempGroups VALUES ('Letland',15,'LV')
  INSERT INTO #TempGroups VALUES ('Litauen',16,'LT')
  INSERT INTO #TempGroups VALUES ('Luxemborg',17,'L')
  INSERT INTO #TempGroups VALUES ('Malta',18,'MT')
  INSERT INTO #TempGroups VALUES ('Norge',19,'N')
  INSERT INTO #TempGroups VALUES ('Polen',20,'PL')
  INSERT INTO #TempGroups VALUES ('Portugal',21,'P')
  INSERT INTO #TempGroups VALUES ('Rumænien',22,'RO')
  INSERT INTO #TempGroups VALUES ('Rusland',23,'RU')
  INSERT INTO #TempGroups VALUES ('Schweiz',24,'CH')
  INSERT INTO #TempGroups VALUES ('Slovakiet',25,'SK')
  INSERT INTO #TempGroups VALUES ('Slovenien',26,'SI')
  INSERT INTO #TempGroups VALUES ('Spanien',27,'E')
  INSERT INTO #TempGroups VALUES ('Storbritanien',28,'GB')
  INSERT INTO #TempGroups VALUES ('Sverige',29,'S')
  INSERT INTO #TempGroups VALUES ('Tjekkiet',30,'CZ')
  INSERT INTO #TempGroups VALUES ('Tyrkiet',31,'TR')
  INSERT INTO #TempGroups VALUES ('Tyskland',32,'D')
  INSERT INTO #TempGroups VALUES ('Ukraine',33,'UA')
  INSERT INTO #TempGroups VALUES ('Ungarn',34,'H')
  INSERT INTO #TempGroups VALUES ('Østrig',35,'A')
  INSERT INTO #TempGroups VALUES ('Andre europæiske lande',36,'OE')
  INSERT INTO #TempGroups VALUES ('Sydafrika',37,'ZA')
  INSERT INTO #TempGroups VALUES ('Andre afrikanske lande',38,'OA1')
  INSERT INTO #TempGroups VALUES ('USA',39,'USA')
  INSERT INTO #TempGroups VALUES ('Canada',40,'CA')
  INSERT INTO #TempGroups VALUES ('Brasilien',41,'BR')
  INSERT INTO #TempGroups VALUES ('Andre amerikanske lande',42,'OA')
  INSERT INTO #TempGroups VALUES ('Folkerepublikken Kina',43,'CN')
  INSERT INTO #TempGroups VALUES ('Japan',44,'JP')
  INSERT INTO #TempGroups VALUES ('Sydkorea',45,'KR')
  INSERT INTO #TempGroups VALUES ('Andre asiatiske lande',46,'OAL')
  INSERT INTO #TempGroups VALUES ('Australien',47,'AU')
  INSERT INTO #TempGroups VALUES ('Andre oceaniske lande',48,'OOL')

	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 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
END  -- End Danish countrygroups
  
CREATE TABLE #TempCountries (CountryName     varchar(30) NOT NULL,
                             CountryCode     varchar(3)  NOT NULL,
                             CurrencyCode    varchar(3)  NOT NULL,
                             CurrencyName    varchar(30) NOT NULL)
  

IF @TheCountryCode = 'DK' OR @TheCountryCode = 'N' OR @TheCountryCode = 'GL' OR @TheCountryCode = 'IRL' OR @TheCountryCode = 'IR'
BEGIN
	INSERT INTO #TempCountries VALUES ('Denmark','DK','DKK','Danske kroner')
	INSERT INTO #TempCountries VALUES ('Faroe Islands','FO','DKK','Danske kroner')
	INSERT INTO #TempCountries VALUES ('Greenland','GL','DKK','Danske kroner')
	INSERT INTO #TempCountries VALUES ('Belgium','B','BEF','Franc')
	INSERT INTO #TempCountries VALUES ('Bulgaria','BG','BGN','Leva')
	INSERT INTO #TempCountries VALUES ('Cyprus','CY','CYP','Pound')
	INSERT INTO #TempCountries VALUES ('Estonia','EE','EEK','Kroon')
	INSERT INTO #TempCountries VALUES ('Finland','FIN','FIM','Markka')
	INSERT INTO #TempCountries VALUES ('France','F','FRF','Franc')
	INSERT INTO #TempCountries VALUES ('Greece','GR','GRD','Drachma')
	INSERT INTO #TempCountries VALUES ('Netherland','NL','NLG','Guilder')
	INSERT INTO #TempCountries VALUES ('Ireland','IRL','IEP','Punt')
	INSERT INTO #TempCountries VALUES ('Iceland','IS','ISK','Krona')
	INSERT INTO #TempCountries VALUES ('Italy','I','ITL','Lira')
	INSERT INTO #TempCountries VALUES ('Latvia','LV','LVL','Lat')
	INSERT INTO #TempCountries VALUES ('Lithuania','LT','LTL','Lita')
	INSERT INTO #TempCountries VALUES ('Luxembourg','L','LUF','Franc')
	INSERT INTO #TempCountries VALUES ('Malta','MT','MTL','Lira')
	INSERT INTO #TempCountries VALUES ('Norway','N','NOK','Krone')
	INSERT INTO #TempCountries VALUES ('Poland','PL','PLN','Zloty')
	INSERT INTO #TempCountries VALUES ('Portugal','P','PTE','Escudo')
	INSERT INTO #TempCountries VALUES ('Romania','RO','RON','New Lei')
	INSERT INTO #TempCountries VALUES ('Russia','RU','RUR','Ruble')
	INSERT INTO #TempCountries VALUES ('Switzerland','CH','CHF','Franc')
	INSERT INTO #TempCountries VALUES ('Slovakia','SK','SKK','Koruna')
	INSERT INTO #TempCountries VALUES ('Slovenia','SI','SIT','Tolar')
	INSERT INTO #TempCountries VALUES ('Spain','E','ESP','Peseta')
	INSERT INTO #TempCountries VALUES ('Great Britain','GB','GBP','Pound Sterling')
	INSERT INTO #TempCountries VALUES ('Sweden','S','SEK','Krona')
	INSERT INTO #TempCountries VALUES ('Czech Republic','CZ','CZK','Koruna')
	INSERT INTO #TempCountries VALUES ('Turkia','TR','TRL','Lira')
	INSERT INTO #TempCountries VALUES ('Germany','D','DEM','Mark')
	INSERT INTO #TempCountries VALUES ('Ukraine','UA','UAK','Hryvnia')
	INSERT INTO #TempCountries VALUES ('Hungary','H','HUF','Forint')
	INSERT INTO #TempCountries VALUES ('Austria','A','ATS','Schilling')
	INSERT INTO #TempCountries VALUES ('Other Europe','OE','OE','')
	INSERT INTO #TempCountries VALUES ('South Africa','ZA','ZAR','Rand')
	INSERT INTO #TempCountries VALUES ('Other Africa','OA1','OA1','')
	INSERT INTO #TempCountries VALUES ('USA','USA','USD','Dollar')
	INSERT INTO #TempCountries VALUES ('Canada','CA','CAD','Dollar')
	INSERT INTO #TempCountries VALUES ('Brazil','BR','BRL','Real')
	INSERT INTO #TempCountries VALUES ('Other America','OA','OA','')
	INSERT INTO #TempCountries VALUES ('China','CN','CNY','Yuan Renminbi')
	INSERT INTO #TempCountries VALUES ('Japan','JP','JPY','Yen')
	INSERT INTO #TempCountries VALUES ('South Korea','KR','KRW','Won')
	INSERT INTO #TempCountries VALUES ('Other Asien','OAL','OAL','')
	INSERT INTO #TempCountries VALUES ('Australia','AU','AUD','Dollar')
	INSERT INTO #TempCountries VALUES ('Other Transatlantic','OOL','OOL','')
	INSERT INTO #TempCountries VALUES ('Liechtenstein','LI','CHF','Franc')
	INSERT INTO #TempCountries VALUES ('Mexico','Mx','MXN','Peso')

	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 @CountryName = 'Germany'
	  BEGIN
	    -- Eksistere som tyskland
	    IF EXISTS (SELECT CountryName FROM Countries WITH (NOLOCK) WHERE CountryName = 'TYSKLAND')
	    BEGIN
	      SELECT @CountryGroupNumber = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupCode = @CountryCode
	      UPDATE Countries SET CountryGroupNumber = @CountryGroupNumber, MarkAsDeleted = 0, CurrencyCode = @CurrencyCode, CurrencyName = @CurrencyName WHERE CountryName = 'TYSKLAND'   
	    END
	    ELSE
	    --Eksistere som Germany
	    IF EXISTS (SELECT CountryName FROM Countries WITH (NOLOCK) WHERE CountryName = @CountryName)
	    BEGIN
	      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
	    ELSE
	    BEGIN
	    -- Findes slet ikke i forvejen
	      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
	    FETCH NEXT FROM db_cur1 INTO @CountryName, @CountryCode, @CurrencyCode, @CurrencyName
	    CONTINUE
	  END
	
	  IF @CountryName = 'Norway'
	  BEGIN
	    -- Eksistere som Norge
	    IF EXISTS (SELECT CountryName FROM Countries WITH (NOLOCK) WHERE CountryName = 'Norge')
	    BEGIN
	      SELECT @CountryGroupNumber = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupCode = @CountryCode
	      UPDATE Countries SET CountryGroupNumber = @CountryGroupNumber, MarkAsDeleted = 0, CurrencyCode = @CurrencyCode, CurrencyName = @CurrencyName WHERE CountryName = 'Norge'   
	    END
	    ELSE
	    --Eksistere som Norway
	    IF EXISTS (SELECT CountryName FROM Countries WITH (NOLOCK) WHERE CountryName = @CountryName)
	    BEGIN
		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
	    ELSE
	    BEGIN
	    -- Findes slet ikke i forvejen
	      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
	    FETCH NEXT FROM db_cur1 INTO @CountryName, @CountryCode, @CurrencyCode, @CurrencyName
	    CONTINUE
	  END
	  IF @CountryName = 'Italy'
	  BEGIN
	    -- Eksistere som Italien
	    IF EXISTS (SELECT CountryName FROM Countries WITH (NOLOCK) WHERE CountryName = 'Italien')
	    BEGIN
	      SELECT @CountryGroupNumber = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupCode = @CountryCode
	      UPDATE Countries SET CountryGroupNumber = @CountryGroupNumber, MarkAsDeleted = 0, CurrencyCode = @CurrencyCode, CurrencyName = @CurrencyName WHERE CountryName = 'Italien'   
	    END
	    ELSE
	    -- Eksistere som Italien
	    IF EXISTS (SELECT CountryName FROM Countries WITH (NOLOCK) WHERE CountryName = 'Italia')
	    BEGIN
	      SELECT @CountryGroupNumber = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupCode = @CountryCode
	      UPDATE Countries SET CountryGroupNumber = @CountryGroupNumber, MarkAsDeleted = 0, CurrencyCode = @CurrencyCode, CurrencyName = @CurrencyName WHERE CountryName = 'Italia'   
	    END
	    ELSE
	    --Eksistere som Italy
	    IF EXISTS (SELECT CountryName FROM Countries WITH (NOLOCK) WHERE CountryName = @CountryName)
	    BEGIN
	      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
	    ELSE
	    BEGIN
	    -- Findes slet ikke i forvejen
	      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
	    FETCH NEXT FROM db_cur1 INTO @CountryName, @CountryCode, @CurrencyCode, @CurrencyName
	    CONTINUE
	  END
	
	  IF @CountryName = 'Sweden'
	  BEGIN
	    -- Eksistere som Sverige
	    IF EXISTS (SELECT CountryName FROM Countries WITH (NOLOCK) WHERE CountryName = 'Sverige')
	    BEGIN
	      SELECT @CountryGroupNumber = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupCode = @CountryCode
	      UPDATE Countries SET CountryGroupNumber = @CountryGroupNumber, MarkAsDeleted = 0, CurrencyCode = @CurrencyCode, CurrencyName = @CurrencyName WHERE CountryName = 'Sverige'   
	    END
	    ELSE
	    --Eksistere som Sweden
	    IF EXISTS (SELECT CountryName FROM Countries WITH (NOLOCK) WHERE CountryName = @CountryName)
	    BEGIN
	      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
	    ELSE
	    BEGIN
	    -- Findes slet ikke i forvejen
	      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
	    FETCH NEXT FROM db_cur1 INTO @CountryName, @CountryCode, @CurrencyCode, @CurrencyName
	    CONTINUE
	  END
	
	  IF NOT EXISTS (SELECT CountryName FROM Countries WITH (NOLOCK) WHERE CountryName = @CountryName) 
	  BEGIN
	    -- landet findes ikke - indsæt det
	    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 
	    -- Landet findes - kontroller at groupnumber er korrekt.
	    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
END

IF @TheCountryCode = 'DK' OR @TheCountryCode = 'IRL' OR @TheCountryCode = 'IR'
BEGIN
	--Hent Hvilket nr de enkelte grupper har fået.
	SELECT @OtherEurope = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupSortNumber = 34
	SELECT @OtherAfrica = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupSortNumber = 36
	SELECT @OtherAmerica = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupSortNumber = 40
	SELECT @OtherAsia = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupSortNumber = 44
	SELECT @OtherOceanic = GroupNumber FROM CountryGroups WITH (NOLOCK) WHERE GroupSortNumber = 46
	
	--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 = 'Bulgaria' or
       @CountryName = 'Croatia' or @CountryName = 'Liechtenstein' or @CountryName = 'Macedonia' or @CountryName = 'Moldova' or @CountryName = 'Romania' 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
END

IF @TheCountryCode = 'DK' OR @TheCountryCode = 'IRL' OR @TheCountryCode = 'IR'
BEGIN
  DEALLOCATE db_cur
  DEALLOCATE db_cur2
END

IF @TheCountryCode = 'DK' OR @TheCountryCode = 'N' OR @TheCountryCode = 'GL' OR @TheCountryCode = 'IRL' OR @TheCountryCode = 'IR'
  DEALLOCATE db_cur1

DROP TABLE #TempGroups
DROP TABLE #TempCountries
