www.webdeveloper.com
Results 1 to 3 of 3

Thread: Determine Most Current Record

  1. #1
    Join Date
    Oct 2006
    Posts
    93

    Determine Most Current Record

    I have a table that contains information regarding documents being uploaded. Periodically, new documents will be uploaded to "replace" the previous document. So I have a document name and an owner that will have multiple rows, but with different other attribute fields.

    I would like to create a view in SQL 2005 that can dynamically determine which document is the most current (determined by the most recently added record ie MAX(ID)).

    Basically, in a view I would like to have a field like....
    IF MAX(ID) for this combination of Document Name & Owner, then true else false
    and name this field something like IsCurrent.

    I'm not sure if this is possible or what the syntax would look like.

    Thanks

  2. #2
    Join Date
    Jan 2009
    Posts
    34
    This should be possible, at a minimum within your code,

    I would grab the list of all docs by the owner..

    SELECT doc FROM table
    WHERE user = user
    ORDER BY id DESC

    then grab the first one in the list within your code
    Hope this helps,

    Larry Darrah
    MS Architect Evangelist

  3. #3
    Join Date
    Jan 2009
    Posts
    14
    For the creation of your view, couldn't you use this select?

    select max(id), owner, document from doctable group by owner, document;

    Then I think you would have the id of the most current document and use that to get the document...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles