Sql query to find activities between Login and Logout time

Hi ,
I have 2 tables as shown below
User Table
ActivityTable
i have  a requirement in which i need to find all the activities done for a particular user inbetween login and logout time  can anybody help me how to write sql query for this .

Is this what you looking for?
DECLARE @User TABLE
userid INT,
date DATETIME,
type VARCHAR(50),
sessionid SMALLINT
DECLARE @ActivityTable TABLE
activityid SMALLINT,
userid SMALLINT,
activity VARCHAR(50),
activitystarttime DATETIME,
activityendtime DATETIME
INSERT INTO @User
(userid,
[date],
[type],
sessionid)
VALUES (1,
'2002-08-25 16:51:25.107',
'Logon',
111),
(1,
'2002-08-25 17:52:25.107',
'LOGOFF',
111),
(2,
'2007-03-08 19:25:21.170',
'Logon',
222),
(2,
'2007-03-08 21:25:21.170',
'LOGOFF',
222),
(3,
'2007-03-08 19:25:21.170',
'Logon',
234);
INSERT INTO @ActivityTable
(activityid,
userid,
activity,
activitystarttime,
activityendtime)
VALUES (234,
1,
'development',
'2002-08-25 16:53:23.101',
'2002-08-25 16:59:23.170'),
(789,
2,
'Testing',
'2007-03-08 19:53:23.180',
'2007-03-08 20:53:23.180'),
(789,
2,
'Lunch',
'2007-03-08 19:53:23.180',
'2007-03-08 20:53:23.180'),
(456,
3,
'Testing',
'2007-03-08 19:53:23.180',
'2007-03-08 20:53:23.180'),
(781,
1,
'Lunch',
'2002-08-25 17:00:23.101',
'2002-08-25 17:30:00.170'),
(781,
1,
'Lunch',
'2002-08-25 21:00:23.101',
'2002-08-25 22:30:00.170');
WITH logon
AS (SELECT date,
userid
FROM @User
WHERE type = 'Logon'),
logoff
AS (SELECT date,
userid
FROM @User
WHERE type = 'LOGOFF')
SELECT at.*
FROM @ActivityTable AT
INNER JOIN logon Lo
ON at.userid = lo.userid
INNER JOIN logoff LF
ON at.userid = lf.userid
WHERE At.activityendtime < LF.date
AND AT.activitystarttime > LO.date
Regards,
Vishal Patel
Blog: http://vspatel.co.uk
Site: http://lehrity.com

Similar Messages

  • Correlate login and logout times in a table

    I have a table LOGINDATA with three columns: USERID, TYPE, and TIMESTAMP.
    USERID stores a unique integer that represents someone who uses the system.
    TYPE is either 1 or 2. 1 represents a login. 2 represents a logout.
    TIMESTAMP is a value that comes from System.currentTimeMillis. It represents the current time in milliseconds since January 1, 1970 (I believe that's the right date).
    I'm trying to create a query to link each login time with its corresponding logout time, so that my resultset has three columns:
    USERID, LOGINTIME, LOGOUTTIME.
    I assume this would involve joining the table to itself, but creating a query to find the closest login and logout times is tricky.
    What I have now is:
    select li.userid, li.logintime, lo.logouttime from
    (select userid, timestamp logintime from logindata where type = 1) li,
    (select userid, timestamp logouttime from logindata where type = 2) lo
    where li.userid=lo.userid
    and li.userid=999999 is the userid of one user.
    This will actually end up being more complicated with missing logout times, but this is a start.

    The data design makes this a very very very messy (and probably slow) query. Fundamentally, I consider designs like this to be broken because they're so hard to get relevant information out of the raw data; in some cases impossible (see comments below).
    The following query works on Oracle database (where TIMESTAMP is a reserved word, so I used EVENTTIME instead) - I tested it with a few rows of data:
    select li.userid, li.logintime, min(possible_logout) logouttime
    from (select userid || to_char(eventtime, 'yyyymmddhh24miss') session_id, userid, eventtime logintime
          from logindata where type = 1) li,
       (select li.userid || to_char(logintime, 'yyyymmddhh24miss') session_id, li.userid, logintime, logouttime possible_logout
        from (select userid, eventtime logintime from logindata where type = 1) li,
             (select userid, eventtime logouttime from logindata where type = 2) lo
        where logintime < logouttime
          and li.userid = lo.userid(+) ) pl
    where li.session_id = pl.session_id (+)
    group by li.userid, li.logintime
    order by li.logintime;Note that this will return the wrong result if for a particular user_id, you have overlapping logins, like:
    time a - login session 1
    time b - login session 2
    time c - logout session 1 or 2
    time d - logout session 2 or session 1
    there is simply no way to tell which logout goes with which login and the query will report that both sessions ended at time c, which is absolutely unacceptable if this is to be a security audit trail... The only way to deal with this is to guarantee at the application layer that no user can be logged in twice.
    Note also that it breaks by returning extra rows if a user somehow manages to log in twice or more at the same moment, whatever the granularity of your TIMESTAMP is... This is because of the join on the generated SESSION_ID; if you get 2 or more of them the same, you get a cartesian product (2 IDs, 4 rows; 5 IDs, 25 rows, etc...)
    It would obviously be a lot cleaner if you stored some sort of unique session_id in your table. Note that the session_ids used for session tracking in J2EE web servers get recycled over time and are therefore unsuitable (by themselves) as unique session ids. And if you store a session id, then you can fix your broken data model and avoid all this mess in the first place by making your table have the columns:
    USER_ID, SESSION_ID, LOGIN_TIME, LOGOUT_TIME
    Insert on login, update on logout...

  • Report for login and logout time

    Dear All,
    Please can some one help me urgently.
    I have to find out users login and logout time over the last six months. I need to find out how many hours per user are being used.  What report do I need to run to find out ?

    Hi,
    Check the system log saved in your system.Normally the basis admin woulfd know better about this .Only they have the access and maintance for it.
    Anyways u can try out some other ways also
    Profile parameters rslg/local/file
    /usr/sap/<SID>/D20/log/SLOG<SAP-instance_number> Specifies the location of the local log on the application server.
    Alternatively try to  table - SYST
    Note:  there are many transaction codes that can be accessed only by super users .do tell me if u have one so that i can give you?

  • Calculating Login and Logout Times - need help

    Hi everyone. I have the first part of this code and can't seem to figure out the time calculation part. What it is - create a code that asks for a user name or social security number, then the person enters up to 6 login and logout times for the day. They also have the option to enter personal time or sick time (neither of which can be over 8 hours). I have all of that complete, but I can't figure out how to get the in and out times and the leave times to calculate. I have 3 pieces of code - here they are:
    Hours:
    import java.util.*;
    public class Hours
         //define states of Hours
         int regularhoursInt = 0;
         int regularminutesInt = 0;
         int overtimehoursInt = 0;
         int overtimeminutesInt = 0;          
         //set hours worked
         public void setHours(int timein, int timeout)
              int temphoursin = timein/100;
              int tempminutesin = timein - timein/100;
              int temphoursout = timeout/100;
              int tempminutesout = timeout - timeout/100;
              GregorianCalendar time1 = new GregorianCalendar(2003, 8, 1, temphoursin, tempminutesin, 0);
              GregorianCalendar time2 = new GregorianCalendar(2003, 8, 1, temphoursout, tempminutesout, 0);
              //store to date
              Date d1 = time1.getTime();
              Date d2 = time2.getTime();
              //store time to long
              long t1 = d1.getTime();
              long t2 = d2.getTime();
              //subtract and convert to seconds
              long time = (t2 - t1)/1000;
              long tempregularLong = 0;
              long tempovertimeLong = 0;
              //see if regular hours are over 8 hours (28800 seconds)
              tempregularLong = time;
              if (tempregularLong > 28800)
                   tempovertimeLong = tempregularLong - 28800;
                   tempregularLong = tempregularLong - tempovertimeLong;
              //convert to hours and minutes
              regularhoursInt = regularhoursInt + (Integer.parseInt(Long.toString(tempregularLong)) / 3600);
              regularminutesInt = regularminutesInt + (Integer.parseInt(Long.toString(tempregularLong)) / (3600 * regularhoursInt));
              overtimehoursInt = overtimehoursInt + (Integer.parseInt(Long.toString(tempovertimeLong)) / 3600);
              overtimeminutesInt = overtimeminutesInt + (Integer.parseInt(Long.toString(tempovertimeLong)) / (3600 * regularhoursInt));     }
         // get regular hours worked
         public int getRegularHours()
              return regularhoursInt;
         // get regular minutes worked
         public int getRegularMinutes()
              return regularminutesInt;
         //get overtime hours worked
         public int getOvertimeHours()
              return overtimehoursInt;
         // get overtime minutes worked
         public int getOvertimeMinutes()
              return overtimeminutesInt;
    Employee:
    public class Employee
         //define states of employee
         String nameString = "";
         String ssnString = "";
         double payrateDouble = 0;
         double hoursworkedDouble = 0;
         double overtimehoursDouble = 0;
         double sickleaveDouble = 0;
         double personalleaveDouble = 0;
         double totalpayDouble = 0;
         //set and get employee name
         public void setName(String name)
              nameString = name;
         public String getName()
              return nameString;
         //set and get employee ssn
         public void setSsn(String ssn)
              ssnString = ssn;
         public String getSsn()
              return ssnString;
         //set and get employee payrate
         public void setPayRate(double payrate)
              payrateDouble = payrate;
         public double getPayRate()
              return payrateDouble;
         //set and get employee hours worked
         public void setHoursWorked(double hoursworked)
              hoursworkedDouble = hoursworked;
         public double getHoursWorked()
              return hoursworkedDouble;
         //set and get employee overtimehours
         public void setOverTime(double overtime)
              overtimehoursDouble = overtime;
         public double getOverTime()
              return overtimehoursDouble;
         //set and get employee sick leave hours
         public void setSickLeave(double sickleave)
              sickleaveDouble = sickleave;
         public double getSickLeave()
              return sickleaveDouble;
         //set and get employee sick leave hours
         public void setPersonalLeave(double personalleave)
              personalleaveDouble = personalleave;
         public double getPersonalLeave()
              return personalleaveDouble;
         //get employees total pay
         public double getTotalPay()
              //calculate regular pay
              totalpayDouble = payrateDouble * hoursworkedDouble;
              //add in any over time pay
              totalpayDouble = totalpayDouble + payrateDouble * 1.5 * overtimehoursDouble;
              //add in any sick time pay
              totalpayDouble = totalpayDouble + payrateDouble * sickleaveDouble;
              //add in any personal leave time pay
              totalpayDouble = totalpayDouble + payrateDouble * personalleaveDouble;
              return totalpayDouble;
    Entry Screen:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    import javax.swing.*;
    import java.util.*;
    import java.text.*;
    //create entryscreen class as a java applet
    public class EntryScreen extends Applet implements ActionListener
         //declare all variables, labels, textfields, and buttons
    //store pay rate to variable payrateDouble
         double payrateDouble = 10.00;
         //store ssn and names to ssnString
         String[][] ssnString ={{"123121234", "234232345", "345343456", "456454567",
              "567565678", "678676789"},{"Jane Doe", "John Doe", "Sam Smith", "Tom Thumb", "Sara Jane", "Cindy Thompson"}};
         //set date format to MM/dd/yy and store in variable formatter
         SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
         //store current date to variable date
         Date date = new Date();
         //using variable formatter store current date to dateString
         String dateString = formatter.format(date);
         //declare all label, Textfields and buttons use in the applet
         JLabel titleLabel;
    JLabel dateLabel;
    JTextField dateTextField;
    JLabel ssnLabel;
    JTextField ssnTextField;
    JLabel timeLabel;
    JLabel inLabel;
    JLabel outLabel;
    JTextField in1TextField;
    JTextField in2TextField;
    JTextField in3TextField;
         JTextField in4TextField;
         JTextField in5TextField;
    JTextField in6TextField;
    JTextField out1TextField;
    JTextField out2TextField;
    JTextField out3TextField;
    JTextField out4TextField;
    JTextField out5TextField;
    JTextField out6TextField;
    JLabel sickLabel;
    JTextField sickTextField;
    JTextField personalTextField;
    JLabel personalLabel;
    JButton okButton;
    JButton clearButton;
    JLabel day1Label;
    JLabel day2Label;
    JLabel day3Label;
    JLabel day4Label;
    JLabel day5Label;
    JLabel day6Label;
         //initialize the applet screen
    public void init()
              //create a custom layout object based on the EntryScreenLayout class
              EntryScreenLayout customLayout = new EntryScreenLayout();
              //set the font for the screen
    setFont(new Font("Helvetica", Font.PLAIN, 12));
    setLayout(customLayout);
         //populate the applet with the labels, textfields, and buttons
              titleLabel = new JLabel("Employee Payroll System");
    add(titleLabel);
    dateLabel = new JLabel("Date (MM/DD/YY):");
    add(dateLabel);
    dateTextField = new JTextField("");
    add(dateTextField);
              //set text in field to current date
              dateTextField.setText(dateString);
    ssnLabel = new JLabel("SSN (Numbers Only):");
    add(ssnLabel);
    ssnTextField = new JTextField("");
    add(ssnTextField);
    timeLabel = new JLabel("Hours Worked (hhmm)");
    add(timeLabel);
    inLabel = new JLabel("In:");
    add(inLabel);
    outLabel = new JLabel("Out");
    add(outLabel);
    in1TextField = new JTextField("");
    add(in1TextField);
    in2TextField = new JTextField("");
    add(in2TextField);
    in3TextField = new JTextField("");
    add(in3TextField);
    in4TextField = new JTextField("");
    add(in4TextField);
    in5TextField = new JTextField("");
    add(in5TextField);
    in6TextField = new JTextField("");
    add(in6TextField);
    out1TextField = new JTextField("");
    add(out1TextField);
    out2TextField = new JTextField("");
    add(out2TextField);
    out3TextField = new JTextField("");
    add(out3TextField);
    out4TextField = new JTextField("");
    add(out4TextField);
    out5TextField = new JTextField("");
    add(out5TextField);
    out6TextField = new JTextField("");
    add(out6TextField);
    sickLabel = new JLabel("Sick Leave Used:");
    add(sickLabel);
    sickTextField = new JTextField("");
    add(sickTextField);
    personalTextField = new JTextField("");
    add(personalTextField);
    personalLabel = new JLabel("Personal Leave Used:");
    add(personalLabel);
         okButton = new JButton("Ok");
         add(okButton);
              okButton.addActionListener(this);
         clearButton = new JButton("Clear");
         add(clearButton);
              clearButton.addActionListener(this);
         day1Label = new JLabel("Day 1:");
         add(day1Label);
         day2Label = new JLabel("Day 2:");
         add(day2Label);
    day3Label = new JLabel("Day 3:");
    add(day3Label);
    day4Label = new JLabel("Day 4:");
    add(day4Label);
    day5Label = new JLabel("Day 5:");
    add(day5Label);
    day6Label = new JLabel("Day 6:");
              add(day6Label);
              //set the size of the applet window as listed in the EntryScreenLayout class
              setSize(getPreferredSize());
         public void actionPerformed(ActionEvent e)
              //get the source object
              Object source = e.getSource();
              //perform if OK button was presses      
              if(source == okButton)
                   int[][] inouttimes = new int[1][5];
                   boolean matchBoolean = false;
                   boolean timeError = false;
                   int locationInt = 0;
                   double[] leavehours = new double[1];
                   String messageString = "";
                   //get the text from the ssnTextField and store to inputString
                   String inputString = ssnTextField.getText();
                   //check to see if inputString matches ssnString array
                   for(int i = 0; i < 6; ++i)
                        //if a match assign variables
                        if (inputString.equals(ssnString[0]))
                             matchBoolean = true;
                             locationInt = i;
                             break;
                        //if not a match
                        else
                             matchBoolean = false;
                   }//end for i
                   //if a SSN match is true than display the name, SSN, total hours, overtime hours, and total pay for hours worked.
                   if (matchBoolean == true)
                        //get the check in/out times, if blank assign a zero
                        Employee temp = new Employee();
                        temp.setName(ssnString[1][locationInt]);
                        temp.setSsn(ssnString[0][locationInt]);
                        temp.setPayRate(payrateDouble);
                        temp.setSickLeave(Double.parseDouble(sickTextField.getText()));
                        temp.setPersonalLeave(Double.parseDouble(personalTextField.getText()));
                        /*inouttimes[0][0] = Integer.parseInt(in1TextField.getText());
                        inouttimes[1][0] = Integer.parseInt(out1TextField.getText();
                        inouttimes[0][1] = Integer.parseInt(in2TextField.getText();
                        inouttimes[1][1] = Integer.parseInt(out2TextField.getText();
                        inouttimes[0][2] = Integer.parseInt(in3TextField.getText();
                        inouttimes[1][2] = Integer.parseInt(out3TextField.getText();
                        inouttimes[0][3] = Integer.parseInt(in4TextField.getText();
                        inouttimes[1][3] = out4TextField.getText();
                        inouttimes[0][4] = in5TextField.getText();
                        inouttimes[1][4] = out5TextField.getText();
                        inouttimes[0][5] = in6TextField.getText();
                        inouttimes[1][5] = out6TextField.getText();
                        for (int x = 0; x < 2; ++x)
                             for (int y = 0; y < 2; ++y)
                                  String temp = String.valueOf(inouttimes[x][y]);
                                  if (temp.equals(""))
                                       inouttimes[x][y] = 0;
                                  if (inouttimes[x][y] < 0 && inouttimes[x][y] > 2400)
                                       timeError = true;          
                                       break;
                             if (timeError = true)
                                  break;
                        messageString = temp.getName() + "\n" + temp.getSsn() + "\n" + temp.getTotalPay();
                   JOptionPane.showMessageDialog(null, messageString);
                   }//if (matchBoolean == true)
                   //if SSN match is false then display error message
                   else
                        JOptionPane.showMessageDialog(null, "There is no listing under that Social Security Number.\n" +
                             "Please verify and re-enter.");                    
              }//end if(source == okButton)
              //perform if the Clear button was pressed
              if(source == clearButton)
                   //clear all the textfields
                   dateTextField.setText("");
                   ssnTextField.setText("");
                   in1TextField.setText("");
                   out1TextField.setText("");
                   in2TextField.setText("");
                   out2TextField.setText("");
                   in3TextField.setText("");
                   out3TextField.setText("");
                   in4TextField.setText("");
                   out4TextField.setText("");
                   in5TextField.setText("");
                   out5TextField.setText("");
                   in6TextField.setText("");
                   out6TextField.setText("");
                   sickTextField.setText("");
                   personalTextField.setText("");
                   //set text in field to current date
                   dateTextField.setText(dateString);
         public static void main(String args[])
              //create new entryscreen object called applet
              EntryScreen applet = new EntryScreen();
         //create new frame for applet called window
              Frame window = new Frame("EntryScreen");
         window.addWindowListener(new WindowAdapter()
                   public void windowClosing(WindowEvent e)
                   //close the applet           
                        System.exit(0);
              //initiate the applet
              applet.init();
    window.add("Center", applet);
    window.pack();
    window.setVisible(true);
    //create entryscreenlayout custom class to position controls on applet screen
    class EntryScreenLayout implements LayoutManager {
    public EntryScreenLayout() {
    public void addLayoutComponent(String name, Component comp) {
    public void removeLayoutComponent(Component comp) {
    public Dimension preferredLayoutSize(Container parent) {
    Dimension dim = new Dimension(0, 0);
    Insets insets = parent.getInsets();
    dim.width = 360 + insets.left + insets.right;
    dim.height = 487 + insets.top + insets.bottom;
    return dim;
    public Dimension minimumLayoutSize(Container parent) {
    Dimension dim = new Dimension(0, 0);
    return dim;
    public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    Component c;
    c = parent.getComponent(0);
    if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+8,192,24);}
    c = parent.getComponent(1);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+48,152,24);}
    c = parent.getComponent(2);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+48,152,24);}
    c = parent.getComponent(3);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+80,152,24);}
    c = parent.getComponent(4);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+80,152,24);}
    c = parent.getComponent(5);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+112,152,24);}
    c = parent.getComponent(6);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+144,72,24);}
    c = parent.getComponent(7);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+144,72,24);}
    c = parent.getComponent(8);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+176,72,24);}
    c = parent.getComponent(9);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+208,72,24);}
    c = parent.getComponent(10);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+240,72,24);}
    c = parent.getComponent(11);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+272,72,24);}
    c = parent.getComponent(12);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+304,72,24);}
    c = parent.getComponent(13);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+336,72,24);}
    c = parent.getComponent(14);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+176,72,24);}
    c = parent.getComponent(15);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+208,72,24);}
    c = parent.getComponent(16);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+240,72,24);}
    c = parent.getComponent(17);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+272,72,24);}
    c = parent.getComponent(18);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+304,72,24);}
    c = parent.getComponent(19);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+336,72,24);}
    c = parent.getComponent(20);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+368,152,24);}
    c = parent.getComponent(21);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+368,72,24);}
    c = parent.getComponent(22);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+400,72,24);}
    c = parent.getComponent(23);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+400,152,24);}
    c = parent.getComponent(24);
    if (c.isVisible()) {c.setBounds(insets.left+104,insets.top+440,72,24);}
    c = parent.getComponent(25);
    if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+440,72,24);}
    c = parent.getComponent(26);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+176,72,24);}
    c = parent.getComponent(27);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+208,72,24);}
    c = parent.getComponent(28);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+240,72,24);}
    c = parent.getComponent(29);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+272,72,24);}
    c = parent.getComponent(30);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+304,72,24);}
    c = parent.getComponent(31);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+336,72,24);}
    I know it is a lot of code, but I am just starting and couldn't think of an easier way to do this.
    Thank you for any help - it is greatly appreciated. You can email me with any code help - [email protected].
    Steph

    My 2 cents, I dunno what it'll be worth.
    I think you should never convert anything until the final moment that you are at actually getting the int or float number of hours.
    Why are you doing all this Gregorian and conversion gymnastics throughout your calculations?
    To get the current time in milliseconds, use either
    java.util.Date d = new java.util.Date();
    or
    long d = System.currentTimeMillis();
    Use this long number for all your calculations, and only at the end convert it. To convert, you can use java.text.SimpleDateFormat, which I find very straightforward to use. I honestly think you should never convert your dates before doing any calculations, only after doing them, otherwise you'll loose precision and make errors for sure.

  • Tracking User login and logout times

    I need to track User Login and Logout times. Does anyone know of a easy way or program to do this?
    thanks
    b

    /Applications/Utilities->Terminal->type in this command, and hit the return key:
    last
    For more information, see http://www.osxfaq.com/tips/unix-tricks/ Week 17.

  • SQL query to find out last login for each database

    Hi everybody,
    I have a view with following columns:
    DatabaseSid, lastLogin, firstLogin.
    I want to now the newest last_login date for every database.
    SID First Login Last Login
    e.g. Database1, 11.11.2011, 01.12.2011
    Database1, 01.04.2012, 01.05.2012
    Database3, 03.03.2004, 03.06.2005
    Database 3 07.09.2012, 12.10.2012
    How can I do a query to find out for eacht DB (DB1, DB2 and so on) the Last_Login Date?
    Thank you in advance
    Steve

    Steve wrote:
    Hi everybody,
    I have a view with following columns:
    DatabaseSid, lastLogin, firstLogin.
    I want to now the newest last_login date for every database.
    SID First Login Last Login
    e.g. Database1, 11.11.2011, 01.12.2011
    Database1, 01.04.2012, 01.05.2012
    Database3, 03.03.2004, 03.06.2005
    Database 3 07.09.2012, 12.10.2012
    How can I do a query to find out for eacht DB (DB1, DB2 and so on) the Last_Login Date?
    Thank you in advance
    SteveI'm curious as to how you collect this information from multiple databases into one database, and of what value the data is once you have it.

  • Find Conflicts between start and end time

    I have a table appointment (appointment_id, start, end ,  Location) will hundreds of records like below
    appointment_id        start                                                    
    end                                            Location
    1                            2015-04-29 10:00:00.000              2015-04-29 12:00:00.000            
             ABC
    2                            2015-03-29 09:00:00.000         2015-03-29 13:00:00.000             
    XYZ
    3                           2015-03-29 10:00:00.000         2015-03-29 11:00:00.000             
    XYZ
    if you see appointment id 2 and 3 they are conflicting with same location
    appointment id2 starts at 9 am and ends at 1pm ,
    but appointment id3 also reserved  same day & same location start at 10am and ends at 11 am ..
    this should not be possible ....
    can you help in finding how many such conflicts are there in the  appointment table ?
    i will have to find a report...
    Thanks

    Hi coolguy123SQL,
    Regarding your description, does the appointments happened in the same prefixed locations with a time span overlap mean a conflict? If my understanding is correct, you may reference the below code.
    DECLARE @myTable TABLE (appointment_id INT, startDateTime DATETIME, endDateTime DATETIME, location VARCHAR(10))
    INSERT INTO @myTable
    SELECT 1, '2015-04-29 10:00:00.000', '2015-04-29 12:00:00.000', 'ABC' UNION ALL
    SELECT 2, '2015-03-29 09:00:00.000', '2015-03-29 09:30:00.000', 'XYZ-123' UNION ALL
    SELECT 3, '2015-03-29 10:00:00.000', '2015-03-29 11:00:00.000', 'XYZ-456' UNION ALL
    SELECT 4, '2015-03-29 11:00:00.000', '2015-03-29 13:00:00.000', 'XYZ-789'
    ;WITH CTE AS
    SELECT appointment_id,startDateTime,endDateTime,location,
    CASE WHEN CHARINDEX('-',location)=0 THEN location ELSE SUBSTRING(location,1,CHARINDEX('-',location)-1) END AS locationID FROM @myTable
    CTE2 AS
    SELECT *, ROW_NUMBER() OVER(PARTITION BY locationID ORDER BY startDateTime) AS seq FROM CTE
    SELECT
    c.appointment_id conflict_appmt_id1,c.startDateTime startDateTime1,c.endDateTime endDateTime1,c.location location1,
    t.appointment_id conflict_appmt_id2,t.startDateTime startDateTime2,t.endDateTime endDateTime2,t.location location2
    FROM CTE2 c JOIN CTE2 t ON c.locationID=t.locationID and c.endDateTime>=t.startDateTime AND c.seq<t.seq
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • View logs in windows server (User login and logout )

    Hi Guys,
    I want to see the user login and logout times to the systems. I want know on which systems (Hostname) they logged into that account. 
    Could you please help me. Thanks in advance

    Hi
     You can check the log's on event viewer console,here is good article for your needs,please check;
    https://support.microsoft.com/en-us/kb/556015?wa=wsignin1.0

  • SQL Query to find menus and submenus attached to responsibility

    Hi,
    I am looking for help to find out a sql query to pull out the list of all the menu's associated with each of the responsibilities assigned to users. Please let me know any SQL query to find out menus attached for responsibilities assigned to users.

    835129 wrote:
    I was asked by my lead to list out responsibilities and attached menus and I was asked to submit the output from production. In the metalink note provided by you it was asked to create table collecting all menu id's and I cannot create any tables in production. Apart from this there were 1000's of users with different responsibilities and different menus. I cannot collect all of the users menu ids.
    I just want to list out responsibilities and attached menus. Is that something you can helpout withhttps://forums.oracle.com/forums/search.jspa?threadID=&q=fnd_responsibility_vl+AND+fnd_menu&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    https://forums.oracle.com/forums/search.jspa?threadID=&q=fnd_responsibility_tl+AND+FND_MENU_ENTRIES_TL&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Please search the forum for these tables/views and you should get many hits:
    FND_MENU_ENTRIES_TL
    FND_MENU_ENTRIES_VL
    FND_RESPONSIBILITY_TL
    FND_RESPONSIBILITY_VL
    Thanks,
    Hussein

  • SQL Query to find DN and phone Load

    Hi All,
    We are using Call Manager 8.6 [one PUB and 4 SUBs] and have different IP phone models .
    IP phone model have different LOAD working with them like few 3905 have cmterm-3905.9-2-2-0 while some have cmterm-3905.9-2-2ES7 .
    Is there any way/SQL Query  to find out what all phone model with DN are running 3905.9-2-2.0 LOAD?
    regds,
    aman

    Hey Aman,
    Hope all is well my friend!
    Just to add a note to my friend Carlo's good info here (+5!)
    Try;
    Device> Device Settings> Firmware Load Information>Device Not Using Default Load
    This will show you any phones that deviate from the "device defaults" Fimware And if you click
    on any device listed here it will show the actual Firmware that is being used on the specified device.
    Cheers!
    Rob

  • Java.sql.SQLException: Fail to convert between UTF8 and UCS2: failUTF8Conv

    Hi all,
    I am writing a servlet that connects to Oracle 8.0.6 through jdbc for jdk1.2 on NT 4.0
    English version and it works fine.
    But when the servlet is deployed to a solaris with Oracle 8.0.5 (not a typo, the oracle on
    NT is 8.0.6 and oracle on solaris is 8.0.5) and jdbc for jdk1.2 (of course, for Solaris),
    the servlet failed with the Exception:
    java.sql.SQLException: Fail to convert between UTF8 and UCS2: failUTF8Conv
    (I am using JRun 3.0 as the application and web server for both NT and Solaris)
    (The database in both the NT and solaris platform are using UTF8 charset)
    My servlet looks like this: (dbConn is a Connection object proved to be connected to Oracle
    in previous segment of the same method):
    String strSQL = "SELECT * FROM test";
    try { Statement stmt = dbConn.createStatement();
    ResultSet rs = stmt.execute(strSQL);
    while (rs.next()) {
    out.println("id = " + rs.getInt("id"));
    System.out.println("id written");
    out.println("name = " + rs.getString("name")); // <-- this is the line the
    exception is thrown
    System.out.println("name written");
    } catch (java.sql.SQLException e) {
    System.out.println("SQL Exception");
    System.out.println(e);
    The definition of the "test" table is:
    create table test(
    id number(10,0),
    name varchar2(30));
    There are about 10 rows exists in the table "test", in which all rows contains ONLY chinese
    characters in the "name" field.
    And when I view the System log, the string "id written" is shown EXACTLY ONCE and then there
    is:
    SQL Exception
    java.sql.SQLException: Fail to convert between UTF8 and UCS2: failUTF8Conv
    That means the resultset is fetch back from the database correctly. The problem arise only
    during the getString("name") method.
    Again, this problem only happens when the servlet is run on the solaris platform.
    At first I would expect there are some strange code shown on the web page rather than having
    an exception. I know that I should use getBytes to convert between different encodings, but
    that's another story.
    One more piece of information: When all the rows contains ascii characters in their "name"
    field, the servlet works perfectly even in solaris.
    If anyone knows why and how to tackle the problem please let me know. You can feel free to
    send email to me at [email protected]
    Many thanks,
    Ben
    null

    Hi all,
    For the problem I previously posted, I found that Oracle had had such bug filed before in Oracle 7.3.2 (something like that) and is classified to be NOT A BUG.
    A further research leads me to the document of Oracle that the error message:
    "java.sql.SQLException: Fail to convert between UTF8 and UCS2: failUTF8Conv"
    is a JDBC driver error message of error number ORA-17037.
    I'm still wondering why this behaviour will happen only in Solaris platform. The servlet on an NT machine I am using (which has an Oracle 8.0.6 and jdbc for jdk 1.2 running) is working just fine. I also suspect that this may be some sort of mistakes from jdbc driver.
    Nevertheless, I have found a way to work around the problem that I cannot get non-English string from Oracle in Solaris and I would like to share it with you all here.
    Before I go on, I found that there are many people out there on the web that encounter the same problem. (Some of which said s/he has been working on this problem for a month). As a result, if you find this way of working around the problem does help you, please tell those who have the same problem but don't know how to tackle. Thanks very much.
    Here's the way I work it out. It's kinda simple, but it does work:
    Instead of using:
    String abc = rs.getString("SomeColumnContainsNonEnglishCharacters");
    I used this:
    String abc = new String(rs.getBytes("SomeColumnContainsNonEnglishCharacters"));
    This will give you a string WITH YOUR DEFAULT CHARSET (or ENCODING) from your system.
    If you want to convert the string read to some other encoding type, say Big5, you can do it like this:
    String abc = new String(rs.getBytes("SomeColumneContainsNonEnglishCharacters"), "BIG5");
    Again, it's simple, but it works.
    Finally, if anyone knows why the fail to convert problem happens, please kindly let me know by leaving a word in [email protected]
    Again, thanks to those of you who had tried to help me out.
    Creambun
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by creambun creambun ([email protected]):
    Hi all,
    I am writing a servlet that connects to Oracle 8.0.6 through jdbc for jdk1.2 on NT 4.0
    English version and it works fine.
    But when the servlet is deployed to a solaris with Oracle 8.0.5 (not a typo, the oracle on
    NT is 8.0.6 and oracle on solaris is 8.0.5) and jdbc for jdk1.2 (of course, for Solaris),
    the servlet failed with the Exception:
    java.sql.SQLException: Fail to convert between UTF8 and UCS2: failUTF8Conv
    (I am using JRun 3.0 as the application and web server for both NT and Solaris)
    (The database in both the NT and solaris platform are using UTF8 charset)
    My servlet looks like this: (dbConn is a Connection object proved to be connected to Oracle
    in previous segment of the same method):
    String strSQL = "SELECT * FROM test";
    try { Statement stmt = dbConn.createStatement();
    ResultSet rs = stmt.execute(strSQL);
    while (rs.next()) {
    out.println("id = " + rs.getInt("id"));
    System.out.println("id written");
    out.println("name = " + rs.getString("name")); // <-- this is the line the
    exception is thrown
    System.out.println("name written");
    } catch (java.sql.SQLException e) {
    System.out.println("SQL Exception");
    System.out.println(e);
    The definition of the "test" table is:
    create table test(
    id number(10,0),
    name varchar2(30));
    There are about 10 rows exists in the table "test", in which all rows contains ONLY chinese
    characters in the "name" field.
    And when I view the System log, the string "id written" is shown EXACTLY ONCE and then there
    is:
    SQL Exception
    java.sql.SQLException: Fail to convert between UTF8 and UCS2: failUTF8Conv
    That means the resultset is fetch back from the database correctly. The problem arise only
    during the getString("name") method.
    Again, this problem only happens when the servlet is run on the solaris platform.
    At first I would expect there are some strange code shown on the web page rather than having
    an exception. I know that I should use getBytes to convert between different encodings, but
    that's another story.
    One more piece of information: When all the rows contains ascii characters in their "name"
    field, the servlet works perfectly even in solaris.
    If anyone knows why and how to tackle the problem please let me know. You can feel free to
    send email to me at [email protected]
    Many thanks,
    Ben<HR></BLOCKQUOTE>
    null

  • I want to find the difference(duration) between logon and logoff time?

    i want to find the difference(duration) between logon and logoff time of below table?
    can any one tell the query to find using self join?
    USR     LOGON_TIME     LOGOFF_TIME
    HR     31-AUG-04 03.04.04.000000 AM     -
    HR     - 31-AUG-04 03.04.14.000000 AM
    Edited by: 794244 on Nov 1, 2010 10:47 PM

    No selfjoin, just analytical functions.
    CREATE TABLe log_time
    (username varchar(20),
    LOGON_TIME timestamp,
    LOGOFF_TIME timestamp);
    insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',sysdate,null);
    insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',null,sysdate+1/38);
    insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',sysdate+2,null);
    insert into  log_time (username,LOGON_TIME,LOGOFF_TIME) values ('HR',null,sysdate+2+14/20);
    commit;
    SELECT username,logon_time,logoff_time, my_logoff_time, my_logoff_time -logon_time,
           time_to_sort
    FROM (
            SELECT username,logon_time, logoff_time,
                   LEAD(logoff_time,1,logon_time) OVER (PARTITION BY username ORDER BY time_to_sort) my_logoff_time,
                   time_to_sort
            FROM (SELECT username,logon_time,logoff_time,NVL(logon_time,logoff_time) time_to_sort
                  FROM log_time)
    where LOGON_TIME is not null     
    ORDER BY  time_to_sort; 
    USERNAME     LOGON_TIME     LOGOFF_TIME     MY_LOGOFF_TIME     MY_LOGOFF_TIME-LOGON_TIME     TIME_TO_SORT
    HR     02.11.10 11:34:56.000000000          02.11.10 12:12:50.000000000     0 0:37:54.0     02.11.10 11:34:56.000000000
    HR     04.11.10 11:34:56.000000000          05.11.10 04:22:56.000000000     0 16:48:0.0     04.11.10 11:34:56.000000000But, if that code which fills that table should better UPDATE than INSERT. You can cover much more issues. (e.g the DB crashes and you get 2 logon but no logoff in a sequence and.....)
    -- andy

  • Sql query to find the balances for a customer account wise.

    Hi,
    Could someone help me with the sql query to find the balances for each customer account wise. This is need to generate the report.
    presently we are using this query, but the output doesnot return the expected result.
    SELECT sum(nvl(ps.acctd_amount_due_remaining,0)) "Balance"
    FROM      ra_cust_trx_line_gl_dist_all gld,
              gl_code_combinations c,
              ar_payment_schedules_all ps,
              RA_CUSTOMER_TRX_ALL rat,
              ra_customers rc
    WHERE      c.CHART_OF_ACCOUNTS_ID = 101
    and gld.code_combination_id = c.code_combination_id
         and rat.CUSTOMER_TRX_ID=gld.CUSTOMER_TRX_ID
         and rat.CUSTOMER_TRX_ID=ps.CUSTOMER_TRX_ID
    and ps.customer_id=rc.customer_id
         and ps.status='OP'
         and ps.gl_date <= :PDATE
         and ps.org_id=:PORGID
         and ps.class in ('GUAR','INV','DM','DEP')
    and c.SEGMENT4=:Account_id
    and ps.customer_id=:Customer_id
    Thanks in advance.
    Kalyan.

    Can someone help us with this.

  • Can anybody provide the SQL query to find the files uploaded in a particular folder?

    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

    Nevin,
    Be great if we could know the version of Portal. For Rel. 1, here's the query
    select id,masterthingid from wwv_things
    where siteid = &site
    and cornerid = &corner
    &site - Content Area id
    &corner - Folder id
    if you don't know the folder id, use
    select id from wwv_corners where siteid = &site
    and name = &folder
    Hope this helps. I have run into this situation before. Usually, the culprits were
    one of the following:
    1. Junk Characters in description of item (caused due to Copy-Paste)
    2. Special Characters in the File name
    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

  • SCOM SQL Query to find Mail Latency (Send/ Receive) Data.

    Hi,
    I unable to find Mail Latency (Send/ Receive) Data in SCOM 2012 SQL Query.
    need your help to find SQL query that fetches below details
    1. Average Time for Accessing Mailbox.
    2. Average Time to Send and Receive Mail.
    Regards,
    Vinoth Kumar.

    Hi Vinoth
    There are no specific tables storing the mailbox related data.
    To find information about Exchange in SCOM you need the Exchange management pack for the version of Exchange you are running, as well as monitoring the Exchange servers.
    When that has been done you can find reports and performance views for Exchange.
    I am unsure if you can find this specific information for Exchange in SCOM, i would look into the management pack. If you cannot find the information, i suggest you consult your Exchange administrator to get this information.
    www.coretech.dk - blog.coretech.dk

Maybe you are looking for

  • HR_INFOTYPE_OPERATION not working when called from Dynamic action

    Hi ,        Senario  : I would like to execute a form from dynamic action which creates a record in 0015 (Additional payment IT) .        I have writen the code as shown below am using FM HR_INFOTYPE_OPERATION . When i execute the program from se38 i

  • Imovie 10: how to move the (movie) library to an external drive

    Hi all, using imovie '11 it wasn't any problem to move the (movie) library to an external drive following these instrcutions: <http://support.apple.com/kb/PH2289?viewlocale=en_US>. After updating to mavericks and imovie 10 I can't find the hard drive

  • Problem with Hiding Columns in JTable

    Hi. Who knows how to hide column in JTable. I try to get column: MyTab.getColumnModel().getColumn(i)But there is no methods like SetVisible(false) What to DO???

  • Planning Horizon Business Content

    Hi, Does anyone know if there is a business content for Planning Horizon for Stock - via transaction MD63/61 ?

  • File Open/Save dialog

    Hi, One of my pet peeves about Jdeveloper and by extension of SQLDeveloper is that the file open/save dialog does not have quick way to navigate to familiar places on my computer like "My Documents" or "Desktop". For eg., in Word, I can navigate to M