Translate

Wednesday, 31 May 2017

sql : cursor , create cursor

declare @_CName varchar(100)
declare _cursor cursor read_only for
select Name from dbSample.dbo.Customers
open _cursor
fetch next from _cursor into @_CName
while @@FETCH_STATUS=0
begin
print @_CName
fetch next from _cursor into  @_CName
end

close _cursor
deallocate _cursor


In Capital Letter

DECLARE @_CNAME VARCHAR(100)
DECLARE _CURSOR CURSOR READ_ONLY FOR
SELECT NAME FROM dbSample.dbo.CUSTOMERS
OPEN _CURSOR
FETCH NEXT FROM _CURSOR INTO @_CNAME
WHILE @@FETCH_STATUS=0
BEGIN
PRINT @_CNAME
FETCH NEXT FROM _CURSOR INTO  @_CNAME
END

CLOSE _CURSOR

DEALLOCATE _CURSOR

No comments:

Post a Comment