Prepending the Document Category to the Path

Prepending the Document Category to the Path

Some systems support Document Categories and others support Folders.


The SQL Script below will prepend the document category into the folder path. 
  1. --When a document has a category, prepend the folder with the document category.
  2. UPDATE
    __M_Documents_Digital_Files
    SET
    --Prepend the Category
    Final_Folder_RelativePath = CONCAT('\', V2.Final_Subject, Final_Folder_RelativePath)
    FROM
    __M_Documents_Digital_Files V1,
    __M_Documents_Digital_Categories V2
    WHERE 1=1
    AND V1.Final_DocumentCategory_Id = V2.Id
  3. --Only Prepend it where there is no folder
  4. AND Final_Folder_RelativePath = '\'
  5. --Don't prepend the category if it has already been prepended.
  6. AND CHARINDEX(
  7. CONCAT('\', V2.Final_Subject, '\'),
  8. V1.Final_Folder_RelativePath
  9. ) = 0


  10. --Replace \\ with \
  11. UPDATE
  12. __M_Documents_Digital_Files
  13. SET
  14. Final_Folder_RelativePath = REPLACE(Final_Folder_RelativePath, '\\', '\')