sql query latest version of document

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lsauravbi
    New Member
    • Mar 2014
    • 8

    sql query latest version of document

    I have this first query which gives the mimetype and sum of their total datasize and count of number of document
    Code:
    SELECT MimeType,
    SUM(DataSize)/1024 as Total_Size_MB,count(DocID) as Total_No_Doc FROM DVersData group by MimeType
    This second query gives the latest version of every document type
    Code:
    SELECT  DocID
               , MAX([Version]) AS [MaxVersion]
        FROM    dversdata (nolock)
        GROUP BY DocID
    There is requirement that the result should have the latest version sum And count included in the result where as first query include all the sum of all versions of document and count.
    how to modify the first query to include only the latest version SUM(DataSize) And count(DocID) ?
    Last edited by Rabbit; Apr 18 '14, 03:16 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    Join the latest version query to the original table to filter for only the most recent.

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      If you need just the last version, would it be just a single record and there's no need to sum anything?


      ~~~ CK

      Comment

      • lsauravbi
        New Member
        • Mar 2014
        • 8

        #4
        I need the sum of all document of particular MIME type..but its should include only the latest version of document

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          I understand that, did you try what I suggested in post #2?

          Comment

          Working...