Solved

How to show the last employee that updated a record

Posted on 2016-09-07
5
42 Views
Last Modified: 2016-09-07
I want to show only the last "EMPLOYEE" that updated in the record. In other words, the last employee date stamp in field dbo.WOLABO01B.date.

SELECT     TOP (100) PERCENT dbo.WOMAST01B.step, dbo.WOMAST01B.wono AS WO, dbo.WOMAST01B.item AS PN, dbo.WOMAST01B.location, 
                      dbo.WOMAST01B.dept AS SHOP, dbo.WOLABO01B.prempl AS EMPLOYEE, SUM(dbo.WOLABO01B.time) AS TIME, DATEDIFF(dd, 
                      dbo.WOMAST01B.recdate, GETDATE()) AS [DAYS LEFT], dbo.WOMAST01B.tat
FROM         dbo.WOMAST01B LEFT OUTER JOIN
                      dbo.WOLABO01B ON dbo.WOMAST01B.wono = dbo.WOLABO01B.wono
WHERE     (dbo.WOMAST01B.dept = 'AVI')
GROUP BY dbo.WOMAST01B.step, dbo.WOMAST01B.wono, dbo.WOMAST01B.item, dbo.WOMAST01B.location, dbo.WOMAST01B.dept, 
                      dbo.WOMAST01B.location2, dbo.WOLABO01B.prempl, DATEDIFF(dd, dbo.WOMAST01B.recdate, GETDATE()), dbo.WOMAST01B.tat
ORDER BY [DAYS LEFT] DESC

Open in new window

Capture.PNG
0
Comment
Question by:maximus1974
  • 2
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
Russell Fox earned 500 total points
ID: 41788266
You can use a subquery:
SELECT TOP (100) PERCENT 
	woma.step
	, woma.wono AS WO
	, woma.item AS PN
	, woma.location
	, woma.dept AS SHOP
	, dbo.WOLABO01B.prempl AS EMPLOYEE
	, SUM(dbo.WOLABO01B.time) AS TIME
	, DATEDIFF(dd, woma.recdate, GETDATE()) AS [DAYS LEFT]
	, woma.tat
	, LastDate = (SELECT TOP 1 [date] FROM dbo.WOLABO01B WHERE wono = woma.wono WHERE [date] IS NOT NULL ORDER BY [date] DESC)
FROM dbo.WOMAST01B woma
	LEFT OUTER JOIN dbo.WOLABO01B wola
		ON woma.wono = wola.wono
WHERE woma.dept = 'AVI'
GROUP BY woma.step
	, woma.wono
	, woma.item
	, woma.location
	, woma.dept
	, woma.location2
	, wola.prempl
	, DATEDIFF(dd, woma.recdate, GETDATE())
	, woma.tat
ORDER BY [DAYS LEFT] DESC

Open in new window

0
 
LVL 40

Expert Comment

by:Sharath
ID: 41788375
Can you provide your expected result?
0
 

Author Comment

by:maximus1974
ID: 41788406
is this statement correct?

LastDate = (SELECT TOP 1 [date] FROM dbo.WOLABO01B WHERE wono = woma.wono WHERE [date] IS NOT NULL ORDER BY [date] DESC)
FROM dbo.WOMAST01B woma

Getting syntax errors.
0
 

Author Comment

by:maximus1974
ID: 41788407
Expected result is no WONO duplicates and one employee which is the last one to clock in.
0
 
LVL 40

Expert Comment

by:Sharath
ID: 41788545
In your SELECT clause, I don't see any DATE column but in your screenshot, you have DATE as the last column after tat. Which column is displaying the DATE in your screenshot.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now