Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 171785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:02:58+00:00 2026-05-11T13:02:58+00:00

I have a table called tblAssetsInUse with the following structure: intPK intAssetID datCheckedOut datCheckedIn

  • 0

I have a table called tblAssetsInUse with the following structure:

intPK      intAssetID      datCheckedOut     datCheckedIn 1          450             1/5/2009          10/5/2009 2          300             2/5/2009          <NULL> 3          200             2/5/2009          <NULL> 4          450             12/5/2009         5/7/2009 

and I have a SP that receives a scanned Asset ID then either Inserts, or Updates to the table for assets being checked Out or In respectively. As you can see datCheckedIn may be Null which is used to work out which assets are currently in use. This procedure works perfectly. I wish to be able to determine what the last asset to be scanned was and also what the last operation to the table was (i.e. Check In or Out). I have some SQL code which finds the row with the most recent date (regardless of which column) and I then use this to join to a separate Assets View, which also works. I just need to be able to work out if the most recent date was in the Checked Out or Checked In column somehow.

SELECT TOP (1) allDates.intPK, MAX(allDates.datLastAction) AS datLastScan,    dbo.viwAssets.strFriendlyName, tblAssetsInUse_join.intAssetID FROM (SELECT intPK, MAX(datCheckedOut) AS datLastAction       FROM dbo.tblAssetsInUse AS tblAssetsInUse_out       GROUP BY intPK        UNION ALL        SELECT intPK, MAX(datCheckedIn) AS datLastAction       FROM dbo.tblAssetsInUse AS tblAssetsInUse_in       GROUP BY intPK) AS allDates  INNER JOIN dbo.tblAssetsInUse AS tblAssetsInUse_join ON allDates.intPK = tblAssetsInUse_join.intPK  INNER JOIN dbo.viwAssets ON tblAssetsInUse_join.intAssetID = dbo.viwAssets.intPK GROUP BY allDates.intPK, dbo.viwAssets.strFriendlyName, tblAssetsInUse_join.intAssetID ORDER BY datLastScan DESC 

Is there a literal value of some kind I can add in so that it flags a bit value in the results perhaps?

Thanks for your help,

Paul Reynolds

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:02:59+00:00Added an answer on May 11, 2026 at 1:02 pm

    Beside from getting the type of operation performed, I think that the whole query could be simplified (and optimized) this way:

    SELECT TOP 1 allDates.intPK, allDates.datLastAction AS datLastScan, allDates.operation, dbo.viwAssets.strFriendlyName, tblAssetsInUse_join.intAssetID FROM (SELECT TOP 1 intPK, intAssetID, datCheckedOut AS datLastAction, 'Out' AS operation   FROM dbo.tblAssetsInUse AS tblAssetsInUse_out   ORDER BY datCheckedOut DESC    UNION ALL    SELECT TOP 1 intPK, intAssetID, datCheckedIn AS datLastAction, 'In' AS operation   FROM dbo.tblAssetsInUse AS tblAssetsInUse_in   ORDER BY datCheckedIn DESC) AS allDates  INNER JOIN   dbo.viwAssets ON allDates.intAssetID = dbo.viwAssets.intPK ORDER BY datLastScan DESC 

    EDIT: also note that by removing the TOP 1 in the first line you get both the last Asset checked in and the last checked out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Importing in Java is only necessary so the compiler knows… May 11, 2026 at 2:52 pm
  • added an answer I don't think it's 64/32 bit error. My Dev machine… May 11, 2026 at 2:52 pm
  • added an answer I'd put it in the DOM first. I'm not sure… May 11, 2026 at 2:52 pm

Related Questions

I have a table called OffDays, where weekends and holiday dates are kept. I
I have a Table called Product and I have the Table StorageHistory . Now,
I have a table called ApprovalTasks... Approvals has a status column I also have
I have a table called BlogPost which has a 1-to-many relationship with the Comment

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.