tips & tricks


Calendario
gennaio 2023
lmmgvsd
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

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: 11.226
  • Views Posts: 55.088
  • Views Gallerie: 2.837
  • n° Posts: 120
  • n° Commenti: 1
Copyright © 2002-2007 - Blogs 2.0
dotNetHell.it | Home Page Blogs
ASP.NET 2.0 Windows 2003