Advertisement

07.26.2007 at 03:18PM PDT, ID: 22724201
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

In line query issues

Asked by trahma in MS SQL Server

Tags:

I'm having an issue trying to write a query to determine the status of users on our website.  When a user logs in, every action is tracked within an action table.  This includes logging in, logging out, and selecting a campaign as far as things we're concerned about.

I'm attempting to determine which users have logged in (done by comparing the last login and logout actions) and then show how long they've logged into a particular campaign.  In an attempt to keep this to one query, I've been stumbling on writing a query to return all of the users that are logged in.  I thought I was on to something when I came up with this query:

SELECT            Emp.LastName, Emp.FirstName, Campaign.cpnname, ActionInfo.SD

FROM            (
                  SELECT            unqEmpID, LastName, FirstName
                  FROM            Employees
                  WHERE            [Type] = 2
                  ) AS Emp

INNER JOIN      (
                  SELECT TOP 1      actiontypeid, actionid, unqEmpID
                  FROM                  actions
                  WHERE                  actiontypeid IN (1, 2)
                  ORDER BY            actionid DESC
                  ) AS Actions

ON                  Emp.UnqEmpID = Actions.unqEmpID

INNER JOIN      (
                  SELECT TOP 1      unqEmpID, actionID, actioninfo, DATEDIFF(ss,actionwhen,getdate()) AS SD
                  FROM                  actions
                  WHERE                  actiontypeid=20
                  ORDER BY            actionid DESC
                  ) AS ActionInfo

ON                  ActionInfo.unqEmpID = Emp.unqEmpID
AND                  ActionInfo.actionid > Actions.actionid

INNER JOIN      (
                  SELECT                  cpnname, cpnid
                  FROM                  campaigns
                  ) AS Campaign

ON                  Campaign.cpnid = ActionInfo.actioninfo

ORDER BY      lastname ASC, firstname ASC

For reference, actiontype 1 is logging in and actiontype 2 is logging out.  Selecting a new campaign is actiontypeid 20.  Lastly, employees of Type = 2 are the ones I'm concerned about.

To summarize, I need to pull all users of type 2 out of the database where actiontypeid 1 has occurred after actiontypeid 2.   My query is programmatically however I know the first inner join is where my problem is.Start Free Trial
[+][-]07.26.2007 at 08:13PM PDT, ID: 19580045

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: query
Sign Up Now!
Solution Provided By: derekkromm
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09.02.2008 at 10:36PM PDT, ID: 22374395

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09.08.2008 at 04:50PM PDT, ID: 22422749

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44