Guest User

Untitled

a guest
Aug 6th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. SQL conversion script causes System.OutOfMemoryException
  2. An error occurred while executing batch. Error message is: Exception of type 'System.OutOfMemoryException' was thrown.
  3.  
  4. SELECT clientid
  5. INTO #Temp
  6. FROM client
  7.  
  8. DECLARE
  9. @iteratorId INT,
  10. @phone NVARCHAR(64),
  11. @fax NVARCHAR(64),
  12. @contactid INT
  13.  
  14. WHILE (SELECT Count(*) FROM #Temp) > 0
  15. BEGIN
  16.  
  17. SELECT TOP 1 @iteratorId = clientid FROM #Temp
  18. SET @contactid = NULL
  19.  
  20. --try and grab the first non null phone number in priority order
  21. SET @phone = ISNULL((
  22. SELECT TOP 1
  23. dayphone
  24. FROM contact c
  25. INNER JOIN dbo.clientcontact cc ON c.contactid = cc.contactid
  26. WHERE
  27. clientid = @iteratorId
  28. AND cc.contacttypeid=2
  29. AND c.dayphone IS NOT NULL
  30. ORDER BY cc.parentclientcontactid, priority DESC
  31. ),'')
  32.  
  33. --try and grab the first non null fax priority order
  34. SET @fax = ISNULL((
  35. SELECT TOP 1
  36. fax
  37. FROM contact c
  38. INNER JOIN dbo.clientcontact cc ON c.contactid = cc.contactid
  39. WHERE
  40. clientid = @iteratorId
  41. AND cc.contacttypeid=2
  42. AND c.fax IS NOT NULL
  43. ORDER BY cc.parentclientcontactid, priority DESC
  44. ),'')
  45.  
  46. IF NOT EXISTS(SELECT * FROM clientcontact WHERE clientid=@iteratorId AND contacttypeid=3 AND priority=1)
  47. BEGIN
  48. INSERT INTO dbo.contact
  49. ( versionnumber ,
  50. createdate ,
  51. firstname ,
  52. lastname ,
  53. title ,
  54. middleinitial ,
  55. dayphone ,
  56. nightphone ,
  57. mobilephone ,
  58. fax ,
  59. securefax ,
  60. extranetusername ,
  61. extranetpassword ,
  62. email ,
  63. active ,
  64. testfaxpagereceived ,
  65. ftpoptionid ,
  66. testresultnotify
  67. )
  68. VALUES ( 0 , -- versionnumber - int
  69. GETDATE() , -- createdate - datetime
  70. NULL , -- firstname - nvarchar(64)
  71. NULL , -- lastname - nvarchar(64)
  72. NULL , -- title - nvarchar(64)
  73. NULL , -- middleinitial - nvarchar(64)
  74. NULL , -- dayphone - nvarchar(64)
  75. NULL , -- nightphone - nvarchar(64)
  76. NULL , -- mobilephone - nvarchar(64)
  77. NULL , -- fax - nvarchar(64)
  78. '' , -- securefax - bit
  79. NULL , -- extranetusername - nvarchar(64)
  80. NULL , -- extranetpassword - nvarchar(64)
  81. NULL , -- email - nvarchar(127)
  82. 0 , -- active - bit
  83. 0 , -- testfaxpagereceived - bit
  84. NULL , -- ftpoptionid - int
  85. NULL -- testresultnotify - bit
  86. )
  87. SET @contactid = @@IDENTITY
  88.  
  89. EXEC dbo.procContactSave
  90. @contactid = @contactid, -- int
  91. @firstname = "General", -- nvarchar(64)
  92. @middleinitial = NULL, -- nvarchar(64)
  93. @nightphone = NULL, -- nvarchar(64)
  94. @lastname = "Info", -- nvarchar(64)
  95. @email = NULL, -- nvarchar(127)
  96. @fax = @fax, -- nvarchar(64)
  97. @testfaxpagereceived = 0, -- bit
  98. @mobilephone = NULL, -- nvarchar(64)
  99. @securefax = 0, -- bit
  100. @active = 1, -- bit
  101. @extranetpassword = NULL, -- nvarchar(64)
  102. @extranetusername = NULL, -- nvarchar(64)
  103. @title = NULL, -- nvarchar(64)
  104. @ftpoptionid = NULL, -- int
  105. @dayphone = @phone, -- nvarchar(64)
  106. @testresultnotify = 0, -- bit
  107. @audituserid = 0 -- int
  108.  
  109. EXEC dbo.procClientContactSave
  110. @clientcontactid = NULL, -- int
  111. @priority = 1, -- int
  112. @clientid = @iteratorId, -- int
  113. @contacttypeid = 3, -- int
  114. @contactid = @contactid, -- int
  115. @audituserid = 0 -- int
  116. END
  117.  
  118. DELETE #Temp Where clientid = @iteratorId -- delete row so we don't loop over it again
  119. END
  120. DROP TABLE #Temp
Add Comment
Please, Sign In to add comment