tips & tricks


Calendario
aprile 2024
lmmgvsd
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

Cursor

Esempio di come usare un cursore:


DECLARE @opttype TABLE (code varchar(100),name varchar(300),systemoid varchar(300),description varchar (500),virtual bit,isdigitalized bit,isexternal bit )


insert into @opttype (Code,Name,SystemOid,Description,Virtual,IsDigitalized,IsExternal) values
('18','internal','test','',0,0,0),
('30','internal','test','',0,0,0),
('80','internal','test','',0,0,0),
('81','internal','test','',0,0,0),
('82','internal','test','',0,0,0)

DECLARE @code varchar(100),@name varchar(300),@systemoid varchar(300),@description varchar (500),@virtual bit,@isdigitalized bit,@isexternal bit


DECLARE optype_cursor CURSOR FOR 
SELECT code,name,systemoid,description,virtual,isdigitalized,isexternal FROM @opttype

OPEN optype_cursor  
FETCH NEXT FROM optype_cursor INTO @code, @name, @systemoid, @description, @virtual, @isdigitalized, @isexternal

WHILE @@FETCH_STATUS = 0  
BEGIN  
      IF NOT EXISTS (SELECT 1 FROM OperationType WHERE Code = @code and SystemOid=@systemoid)
BEGIN
INSERT INTO OperationType 
Code,Name,SystemOid,Description,Virtual,IsDigitalized,IsExternal)
VALUES 
(@code, @name, @systemoid, @description, @virtual, @isdigitalized, @isexternal);
END

      FETCH NEXT FROM optype_cursor INTO @code, @name, @systemoid, @description, @virtual, @isdigitalized, @isexternal
END 

CLOSE optype_cursor  
DEALLOCATE optype_cursor 




Categoria: SQLServer
giovedì, 11 giu 2020 Ore. 12.26
Archivio Posts
Anno 2020

Anno 2018

Anno 2015

Anno 2013

Anno 2011

Anno 2010

Anno 2009

Anno 2008
Statistiche
  • Views Home Page: 13.319
  • Views Posts: 56.025
  • Views Gallerie: 2.837
  • n° Posts: 117
  • n° Commenti: 1
Copyright © 2002-2007 - Blogs 2.0
dotNetHell.it | Home Page Blogs
ASP.NET 2.0 Windows 2003