Complex SQL 05 Query
I need big help with this logic...I am not familiar with looping in SQL...functions..
I have six tables..
CCFUser TB: {First_name,Last_Name,EID, Work_Status,CSGID,CCFRole,ModifyDate, LoginDate,CCFLevelID }
Snapshot TB: {SnapshotID,pDeptID....}
Sheet Tb : { SnapshotID,EID....}
Department :{ Department,DeptID }
User_TBL : {First_Name,Last_Name,User_ID,SecurityLevel_ID,LastLogIn,DeptID}
DeptUser: {User_ID,DeptID}
------------
The requirements:
Display all the fields on CCFUser and Department.Department
Loop thru ccfuser (make sure there are on sheet , snaphot and department table)
If CCFUser.CCFLevelID EQ 4
Then go to user_tbl table using first_name and last_name pick the lastloginDate if Department.DeptID is accesstible by the current user on DeptUser.
if yes return user_tbl.lastloginDate
--------
Table relationships:
CFFuser.EID = Sheet.EID
CCFUser.First_Name = User_Tbl.first_name
CCFUser.Last_Name = User_Tbl.Last_name
CCFUser.CCFLevelID = User_Tbl.SecurityLevel_ID
Snapshot.SnapshotID = Sheet.SnapshotID
Department.DeptID = Snaphot.pDeptID
User_TBL.user_id =DeptUser.User_ID
Department.DeptID =DeptUser.DeptID
