Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IF OBJECT_ID('tempdb..#MyTable') IS NOT NULL
- DROP TABLE #MyTable
- SELECT *
- INTO #MyTable
- FROM (
- SELECT '000000002' AS col1, 'Ч1.2020.16.01' AS col2, '2020-04-15 00:00:00.000' AS col3
- UNION
- SELECT '000000002' AS col1, 'Ч1.2020.17.01' AS col2, '2020-04-22 00:00:00.000' AS col3
- ) q
- -- SELECT * FROM [#MyTable]
- DECLARE @col1 VARCHAR(100),
- @col2 VARCHAR(100),
- @col3 DATETIME
- DECLARE MyCursor CURSOR FOR
- SELECT DISTINCT
- col1,
- col2,
- MIN(col3) AS col3
- FROM [#MyTable]
- GROUP BY col1,
- col2
- ORDER BY col3 ASC
- OPEN MyCursor
- FETCH NEXT FROM MyCursor
- INTO @col1, @col2, @col3
- WHILE @@FETCH_STATUS = 0
- BEGIN
- EXEC [dbo].[SomeSP] @col1, @col2, @col3
- FETCH NEXT FROM MyCursor
- INTO @col1, @col2, @col3
- END
- CLOSE MyCursor
- DEALLOCATE MyCursor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement