Microsoft
Software
Hardware
Network
Question : query to get previous field (similar to crystal 'Previous (fld)' or 'Next(fld)' )
Hi experts,
I have this two tables that I need to Join and I need to get Next field in the next record. Next field is based on the Date field of the following record.
Here are my tables and the result I need.
Table1:
ResID Class
ALTJ 80
Table2:
ResID Date Room
ALTJ 3/4/2005 StudioA
ALTJ 7/3/2005 StudioC
I need to get:
TableResult:
ResID Class Date Room NextDateFld
ALTJ 80 3/4/2005 StudioA 7/3/2005
ALTJ 80 7/3/2005 StudioC
The last NextDateFld is NULL because there is no next date for that ResID (no other record)
Thanks for any suggestions
cm
Answer : query to get previous field (similar to crystal 'Previous (fld)' or 'Next(fld)' )
Since the NextDateFld is a derived column, you cannot include that in the WHERE clause. One thing you can do is the following:
SELECT * FROM (
SELECT DISTINCT A.ResID, A.Class, B.Date, B.Room,
ISNULL((SELECT MIN(Date) FROM Table2 C WHERE A.ResID = C.ResID AND
C.Date > B.Date), A.LastDate) AS NextDateFld
FROM Table1 A INNER JOIN Table2 B
ON A.ResID = B.ResID) A
WHERE NextDateFld != '01/01/2000'
Random Solutions
jquery and php
Microsoft, NTFS Permissions, Windows 2003 R2, PowerShell, recursive search for folder, not file, ACLs on 200,000 folders
Generic Host Process for Win32 Services Problem (not virus)
Setting Internet Explorer temporary internet files path via Group Policy
Messenger Email Inbox link after SP2
Error during initial Ruby on Rails db rake
SqlServer really slow with big table?
Remotely add domain admins to local admins
Cell Shading (Cartoon) Look in Flash
Exchange Problems