Advertisement
Guest User

Untitled

a guest
Aug 21st, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. SET NOCOUNT ON;
  2.  
  3. DECLARE @airport_set_id int, @airport_set_name nvarchar(50),
  4. @airport_code nvarchar(50), @country_code nvarchar(50), @country_airport_code nvarchar(50);
  5.  
  6. PRINT '{'
  7. --SELECT @message = '{'
  8.  
  9. DECLARE airport_set_cursor CURSOR FOR
  10. SELECT SegmentationAirportSetID, SegmentationAirportSetName
  11. FROM [ConfigurationMaster].[dbo].[SegmentationAirportSet]
  12. ORDER BY SegmentationAirportSetName;
  13.  
  14. OPEN airport_set_cursor
  15.  
  16. FETCH NEXT FROM airport_set_cursor
  17. INTO @airport_set_id, @airport_set_name
  18.  
  19. WHILE @@FETCH_STATUS = 0
  20. BEGIN
  21. PRINT ' "' +
  22. @airport_set_name + '":['
  23. --SELECT @message = @message + ' "' +
  24. -- @airport_set_name + '":['
  25. -- Declare an inner cursor based
  26. -- on airport_set_id from the outer cursor.
  27.  
  28. DECLARE airport_set_airport_cursor CURSOR FOR
  29. SELECT ASA.AirportCode
  30. FROM [ConfigurationMaster].[dbo].[SegmentationAirportSetAirport] ASA
  31. WHERE ASA.SegmentationAirportSetId = @airport_set_id
  32.  
  33. OPEN airport_set_airport_cursor
  34. FETCH NEXT FROM airport_set_airport_cursor INTO @airport_code
  35. DECLARE @message varchar(max) = '', @message2 varchar(max) = '', @message3 varchar(max) = '', @message4 varchar(max)
  36. IF @@FETCH_STATUS <> 0
  37. PRINT ' <<None>>'
  38.  
  39. WHILE @@FETCH_STATUS = 0
  40. BEGIN
  41. --PRINT @airport_set_name + ': ' + @airport_code
  42. --print LEN(@message)
  43. SELECT @message = @message + '"' + @airport_code + '",'
  44. if(LEN(@message) > 7990)
  45. BEGIN
  46. PRINT @message
  47. SET @message = ''
  48. END
  49.  
  50. FETCH NEXT FROM airport_set_airport_cursor INTO @airport_code
  51. END
  52. CLOSE airport_set_airport_cursor
  53. DEALLOCATE airport_set_airport_cursor
  54.  
  55. --Remove the last comma(',')
  56. SELECT @message = LEFT(@message, LEN(@message)-1)
  57. PRINT @message
  58. PRINT '],'
  59.  
  60. -- Get the next airportset.
  61. FETCH NEXT FROM airport_set_cursor
  62. INTO @airport_set_id, @airport_set_name
  63. END
  64. --SELECT @message = LEFT(@message, LEN(@message)-1)
  65. CLOSE airport_set_cursor;
  66. DEALLOCATE airport_set_cursor;
  67.  
  68. PRINT '}'
  69. --SELECT @message = @message + '}'
  70. --PRINT @message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement