Dynamicweb kopiering af nyhedskategorier med tilhørende nyheder

Havde lige en lille opgave for en kunde, som jeg synes jeg vil dele, da det kan være et helt uoverskueligt stykke arbejde som kan klares på langt kortere tid, hvis man har en database adgang.

Udfordringen for kunden var at kopiere en nyhedskategori med alle underliggende nyheder over til en ny kategori til oversættelse.

Vi fik så kigget lidt på databasen og fik fundet frem til følgende SQL som udfører hele opgaven og tilføjer en “-Copy”-postfix på kategorien.

   1:  declare @categoryID as int 
   2:  SET @categoryID = 71 -- The Category we Copy 
   3:   
   4:  declare @newNewsCatID as int -- The new Copied CategoryID 
   5:  declare @NewsMaxID as int -- The NewsID we have come to and the copied news needs to be 
   6:  -- updated where NewsID is larger than this 
   7:   
   8:  -- Initialize from where we begin with new rows 
   9:  SET @NewsMaxID = (SELECT MAX(News.NewsID) FROM News) 
  10:   
  11:  INSERT INTO [NewsCategory] (
  12:       [NewsCategoryName],
  13:       [NewsCategoryApprovalType],
  14:       [NewsCategoryAccess],
  15:       [NewsCategoryDescription],
  16:       [NewsCategoryAreaIDs]) 
  17:       (select    
  18:            NewsCategory.NewsCategoryName +'-Copy',
  19:            NewsCategory.NewsCategoryApprovalType, 
  20:            NewsCategory.NewsCategoryAccess, 
  21:            NewsCategory.NewsCategoryDescription,
  22:            NewsCategory.NewsCategoryAreaIDs 
  23:       from NewsCategory 
  24:       WHERE NewsCategory.NewsCategoryID = @categoryID ) 
  25:  SET @newNewsCatID = (SELECT MAX(NewsCategory.NewsCategoryID) FROM NewsCategory) 
  26:   
  27:  INSERT INTO News 
  28:             ([NewsCategoryID] 
  29:             ,[NewsActiveFrom] 
  30:             ,[NewsActiveTo] 
  31:             ,[NewsActive] 
  32:             ,[NewsArchive] 
  33:             ,[NewsHeading] 
  34:             ,[NewsManchet] 
  35:             ,[NewsAuthor] 
  36:             ,[NewsText] 
  37:             ,[NewsImage] 
  38:             ,[NewsInitials] 
  39:             ,[NewsCreatedDate] 
  40:             ,[NewsUpdatedDate] 
  41:             ,[NewsDate] 
  42:             ,[NewsTemplateID] 
  43:             ,[NewsSmallImage] 
  44:             ,[NewsLink] 
  45:             ,[NewsApprovalType] 
  46:             ,[NewsApprovalState] 
  47:             ,[NewsVersionTimeStamp] 
  48:             ,[NewsLinkPopup] 
  49:             ,[NewsUserCreate] 
  50:             ,[NewsUserEdit] 
  51:             ,[NewsImageText]) 
  52:       (SELECT 
  53:             NewsCategoryID, 
  54:             NewsActiveFrom, 
  55:             NewsActiveTo, 
  56:             NewsActive, 
  57:             NewsArchive, 
  58:             NewsHeading, 
  59:             NewsManchet, 
  60:             NewsAuthor, 
  61:             NewsText, 
  62:             NewsImage, 
  63:             NewsInitials, 
  64:             NewsCreatedDate, 
  65:             NewsUpdatedDate, 
  66:             NewsDate, 
  67:             NewsTemplateID, 
  68:             NewsSmallImage, 
  69:             NewsLink, 
  70:             NewsApprovalType, 
  71:             NewsApprovalState, 
  72:             NewsVersionTimeStamp, 
  73:             NewsLinkPopup, 
  74:             NewsUserCreate, 
  75:             NewsUserEdit, 
  76:             NewsImageText FROM News WHERE News.NewsCategoryID = @categoryID ) 
  77:  UPDATE News SET NewsCategoryID = @newNewsCatID 
  78:  WHERE NewsID > @NewsMaxID AND NewsCategoryID=@categoryID

 

sql_file Download SQL

 

God fornøjelse med kopiering.

,

En Kommentar

Skriv et svar

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>