From e4a0e4e0c179e64f18d53c560e259917fb1588fd Mon Sep 17 00:00:00 2001 From: Sebastian Pfliegel Date: Fri, 12 Jan 2018 21:39:17 +0100 Subject: [PATCH] Add cursor snippet (#475) * Add cursor snippet * Workaround to avoid issue #480 Remove SELECT and tab to the place for custom code --- extensions/mssql/snippets/mssql.json | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/extensions/mssql/snippets/mssql.json b/extensions/mssql/snippets/mssql.json index 2fc11e7e0b..46b7aeda18 100644 --- a/extensions/mssql/snippets/mssql.json +++ b/extensions/mssql/snippets/mssql.json @@ -243,6 +243,33 @@ "description": "Lists all the columns and their types for tables matching a LIKE statement" }, + "Declare a cursor": { + "prefix": "sqlCursor", + "body": [ + "-- Declare a cursor for a Table or a View '${1:TableOrViewName}' in schema '${2:SchemaName}'", + "DECLARE @Column1 NVARCHAR(50), @Column2 NVARCHAR(50)", + "", + "DECLARE db_cursor CURSOR FOR", + "SELECT Column1, Column2", + "FROM $2.$1", + "", + "OPEN db_cursor", + "FETCH NEXT FROM db_cursor INTO @Column1, @Column2", + "", + "WHILE @@FETCH_STATUS = 0", + "BEGIN", + "\t-- add instructions to be executed for every row", + "\t$3", + "\tFETCH NEXT FROM db_cursor INTO @Column1, @Column2", + "END", + "", + "CLOSE db_cursor", + "DEALLOCATE db_cursor", + "GO" + ], + "description": "Declare a cursor" + }, + "Show space used by tables": { "prefix": "sqlGetSpaceUsed", "body": [