Guest User

Untitled

a guest
Jan 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. /* The queries below use data in a temp table, so at a minimum execute the queries for the temp table, and then use one or more of the queries on the BINARY table */
  2.  
  3. /*** CREATE THE TEMP TABLE ***/
  4. /* Clear the temp table to be sure */
  5. If(OBJECT_ID('tempdb..#CURRENT_ITEM_BINARIES') Is Not Null)
  6. Begin
  7. Drop Table #CURRENT_ITEM_BINARIES
  8. End
  9.  
  10. /* figure out which binaries are used by current (not old) versions of items */
  11. SELECT BINARY_ID as CURRENT_BINARY_ID
  12. ,CONCAT('tcm:', [PUBLICATION_ID], '-', [ITEM_REFERENCE_ID], '-', [ITEM_TYPE]) as ITEM_TCM_ID
  13. ,CONCAT('tcm:', [PUBLICATION_ID], '-', [ITEM_REFERENCE_ID], '-', [ITEM_TYPE], '-v', [VERSION]) as MAX_ITEM_VERSION,
  14. TITLE
  15. INTO #CURRENT_ITEM_BINARIES
  16. FROM [Tridion_CM].[dbo].[ITEMS] I1
  17. WHERE I1.VERSION = (SELECT MAX(VERSION) FROM [ITEMS] I2 WHERE I2.PUBLICATION_ID = I1.PUBLICATION_ID AND I2.ITEM_REFERENCE_ID = I1.ITEM_REFERENCE_ID)
  18. AND BINARY_ID IS NOT NULL;
  19.  
  20. /*** GET INFORMATION ABOUT CURRENT ITEMS ***/
  21. /* show info about binaries which are used in current versions of items */
  22. SELECT [ID] as BINARY_ID, ([BINARIES].[CONTENT_SIZE] / 1024) AS SIZE_KB
  23. ,(SELECT TOP 1 (CONCAT('tcm:', [PUBLICATION_ID], '-', [ITEM_REFERENCE_ID], '-', [ITEM_TYPE]))
  24. FROM ITEMS I2
  25. WHERE I2.[BINARY_ID] = [BINARIES].[ID]
  26. ORDER BY I2.[VERSION]) AS ITEM_TCM_ID
  27. ,(SELECT TOP 1 I3.[TITLE]
  28. FROM ITEMS I3
  29. WHERE I3.[BINARY_ID] = [BINARIES].[ID]
  30. ORDER BY I3.[VERSION]) AS TITLE
  31. FROM BINARIES
  32. WHERE ID IN (SELECT CURRENT_BINARY_ID FROM #CURRENT_ITEM_BINARIES);
  33.  
  34. /* show total size of binaries which are used in current versions of items */
  35. SELECT SUM(([BINARIES].[CONTENT_SIZE] / 1024)) AS TOTAL_SIZE_KB
  36. FROM BINARIES
  37. WHERE ID IN (SELECT CURRENT_BINARY_ID FROM #CURRENT_ITEM_BINARIES);
  38.  
  39. /*** GET INFORMATION ABOUT OLD ITEMS ***/
  40. /* show info about binaries which are only used in old versions of items */
  41. SELECT [ID] as BINARY_ID, ([BINARIES].[CONTENT_SIZE] / 1024) AS SIZE_KB
  42. ,(SELECT TOP 1 (CONCAT('tcm:', [PUBLICATION_ID], '-', [ITEM_REFERENCE_ID], '-', [ITEM_TYPE]))
  43. FROM ITEMS I2
  44. WHERE I2.[BINARY_ID] = [BINARIES].[ID]
  45. ORDER BY I2.[VERSION]) AS ITEM_TCM_ID
  46. ,(SELECT TOP 1 I3.[TITLE]
  47. FROM ITEMS I3
  48. WHERE I3.[BINARY_ID] = [BINARIES].[ID]
  49. ORDER BY I3.[VERSION]) AS TITLE
  50. FROM BINARIES
  51. WHERE ID NOT IN (SELECT CURRENT_BINARY_ID FROM #CURRENT_ITEM_BINARIES);
  52.  
  53. /* show total size of binaries which are only used in old versions of items */
  54. SELECT SUM(([BINARIES].[CONTENT_SIZE] / 1024)) AS TOTAL_SIZE_KB
  55. FROM BINARIES
  56. WHERE ID NOT IN (SELECT CURRENT_BINARY_ID FROM #CURRENT_ITEM_BINARIES);
Add Comment
Please, Sign In to add comment