Advertisement
Hippolito

Untitled

Jul 20th, 2020
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. IF OBJECT_ID('tempdb..#MyTable') IS NOT NULL
  2. DROP TABLE #MyTable
  3.  
  4. SELECT *
  5. INTO #MyTable
  6. FROM (
  7. SELECT '000000002' AS col1, 'Ч1.2020.16.01' AS col2, '2020-04-15 00:00:00.000' AS col3
  8. UNION
  9. SELECT '000000002' AS col1, 'Ч1.2020.17.01' AS col2, '2020-04-22 00:00:00.000' AS col3
  10. ) q
  11.  
  12. -- SELECT * FROM [#MyTable]
  13.  
  14. DECLARE @col1 VARCHAR(100),
  15. @col2 VARCHAR(100),
  16. @col3 DATETIME
  17.  
  18. DECLARE MyCursor CURSOR FOR
  19.  
  20. SELECT DISTINCT
  21. col1,
  22. col2,
  23. MIN(col3) AS col3
  24. FROM [#MyTable]
  25. GROUP BY col1,
  26. col2
  27. ORDER BY col3 ASC
  28.  
  29. OPEN MyCursor
  30.  
  31. FETCH NEXT FROM MyCursor
  32. INTO @col1, @col2, @col3
  33.  
  34. WHILE @@FETCH_STATUS = 0
  35.  
  36. BEGIN
  37.  
  38. EXEC [dbo].[SomeSP] @col1, @col2, @col3
  39.  
  40. FETCH NEXT FROM MyCursor
  41. INTO @col1, @col2, @col3
  42.  
  43. END
  44. CLOSE MyCursor
  45. DEALLOCATE MyCursor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement