Created
March 26, 2012 16:15
-
-
Save roalcantara/2206227 to your computer and use it in GitHub Desktop.
SQLServer - Procedure com tabela temporária e cursor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [BANK] | |
CREATE PROCEDURE [dbo].[spTbTempAndCursor] | |
AS | |
BEGIN | |
SET NOCOUNT ON; | |
CREATE TABLE #TB_TEMP ( | |
[ID] [varchar](10) NOT NULL, | |
[NAME] [varchar](10) NOT NULL | |
) ON [PRIMARY] | |
DECLARE @ID varchar(10), | |
@NAME varchar(10) | |
DECLARE USER_CURSOR CURSOR FOR SELECT ID, NAME FROM TB_USER OPEN USER_CURSOR | |
FETCH NEXT FROM USER_CURSOR INTO @ID, @NAME | |
WHILE @@FETCH_STATUS = 0 BEGIN | |
PRINT N'ID:' + @ID + ', NAME:' + @NAME; | |
FETCH NEXT FROM USER_CURSOR INTO @ID, @NAME | |
END | |
CLOSE USER_CURSOR | |
DEALLOCATE USER_CURSOR | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment