Turvenn.no
Webutvikler kurs ASP.NET, C#, CSS mm.

WebRessurs.no - Webprogrammering og ressurs innen ASP, ASP.NET, PHP, SQL, HTML, CSS, Javascript, XML, C#, VB, Flash  mm.

Brukernavn: 
Passord:

Registrèr deg Glemt passord?
Logg deg inn




  ASP.net (199)
  ASP 3.0 (111)
  PHP (30)
  HTML (66)
  SQL (89)
  CSS (46)
  XML (7)
  JavaScript (78)
  Diverse kode (13)


  Programmering (22)
  System og drift (15)
  Trafikk og inntekt (11)
  Guider og tips (22)
  Nyttig lesestoff (23)
  Web forum (604)
  Link galleri (565)


  ASP.NET kurs(5)
  CSS kurs (2)
  JQuery kurs (2)


  Øk trafikken (8)
  Facebook App. (4)
  Microsoft CEO (6)


  Server & web
  Internett & epost
  Systemverktøy
  Sikkerhet
  Fildeling
  Lyd & media
  Diverse software


  Domenesalg
  Metagenerator
  Websikre farger
  WebMail


  Bli medlem!
  Siste innlegg
  Gjestebok
  Tips en venn
  Kontakt oss
  Forsiden




Kode Artikler
Linker


Mål internetthastigheten din.


Kopiere innholdet i en og samme tabell, med èn endring.

av Øyvind A. Isaksen
 
Denne koden har til hensikt å loope igjennom data i en tabell,endre ett felt (siteID), og deretter inserte dataene igjen. Dermed får vi en kopi, men endret siteID! Nøkkelord er: CURSOR og FETCH.

------------------------------
Eksempel 1
------------------------------

DECLARE @tmpFunction nvarchar(255)
DECLARE @tmpAliasId int
DECLARE @tmpName nvarchar(255)
DECLARE @tmpStatusID int
DECLARE @tmpTypeId int


DECLARE templatecursor CURSOR LOCAL FOR
SELECT col_function, col_templatealiasId, col_name, col_templatestatusId, col_templatetypeId FROM m0_template WHERE col_siteid = 22

OPEN templatecursor
FETCH NEXT FROM templatecursor INTO @tmpFunction,@tmpAliasId, @tmpName, @tmpStatusID, @tmpTypeId
WHILE @@FETCH_STATUS = 0

BEGIN
INSERT INTO m0_template(col_function, col_templatealiasId, col_name, col_templatestatusId, col_templatetypeId, col_siteid) VALUES(@tmpFunction,@tmpAliasId, @tmpName, @tmpStatusID, @tmpTypeId, 21)

<!--Test: PRINT @tmpFunction-->
FETCH NEXT FROM templatecursor INTO @tmpFunction,@tmpAliasId, @tmpName, @tmpStatusID, @tmpTypeId
END

CLOSE templatecursor
DEALLOCATE templatecursor


------------------------------
Eksempel 2
------------------------------

Declare @tmpTitle varchar(256)
Declare @tmpText varchar(1024)

Declare minLeser CURSOR FOR
Select title,text from tblInfo where siteID=1

Open minLeser
Fetch NEXT from minLeser into @tmpTitle,@tmpText while @@FETCH_STATUS = 0

Begin
Insert into tblInfo (title,text,siteID) values (@tmpTitle,@tmpText,2)
Fetch Next from minLeser INTO @tmpTitle,@tmpText
End

close minLeser
DEALLOCATE minLeser

WebRessurs.no anbefaler:    StackOverflow.com | Experts-Exchange.com | W3schools | ASP.NET | Codeproject | 4Guys
WebRessurs.no er utviklet og drives av SoftMaker
Sett som startside: [ ]. Bokmerk denne siden: [ klikk ]. Sitemap. http://twitter.com/webressurs_no/. Antall brukersesjoner: 14106807.
Copyright WebRessurs.no © 2003 - 2018
Jobbsøk.no - Jobbsøknad, CV, intervju, tips og lenker