Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8866311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:45:27+00:00 2026-06-14T16:45:27+00:00

I am a new developer in ASP.NET with C#. I developed a web-based application

  • 0

I am a new developer in ASP.NET with C#. I developed a web-based application for one of the companies, and now I am required to develop a log that shows the number of unique people accessing the system. For example, Employees A and B from Division AA accessed the system today. Employee A accessed the system twice at the same day. The log should show that there are two employees from Division AA accessed the system today not three.

I have the following database design:

Employee Table: Username, Name, DivisionCode (DivisionCode is a foreign key to SapCode)
Divisions Table: SapCode DivisionShortcut   
Log Table: ID, Username, DateTimeAccessing

I wrote the following query that shows the username, employee name, division and DateTimeAccessing:

SELECT     dbo.[Log].Username, dbo.employee.Name, dbo.Divisions.DivisionShortcut, dbo.[Log].DateTimeAccessing
FROM         dbo.employee INNER JOIN
                      dbo.[Log] ON dbo.employee.Username = dbo.[Log].Username INNER JOIN
                      dbo.Divisions ON dbo.employee.DivisionCode = dbo.Divisions.SapCode

The query should show the number of employees who accessed the system everyday based on division and date such as:

At Nove 21, Division AA = 2    
   Nove 21, Division BB = 7    
   Nove 20, Division AA = 12 and so on

So how to do that?

*UPDATE:*
I am using now the following query:

SELECT     CONVERT(varchar(10), l.DateTimeAccessing, 120) AS Date, d.DivisionShortcut, COUNT(DISTINCT l.Username) AS Cnt
FROM         dbo.employee AS e INNER JOIN
                      dbo.[Log] AS l ON e.Username = l.Username RIGHT OUTER JOIN
                      dbo.Divisions AS d ON e.DivisionCode = d.SapCode
GROUP BY CONVERT(varchar(10), l.DateTimeAccessing, 120), d.DivisionShortcut

The problem now is for example if I want to see the statistics for today or Nov 10 for all divisions, the date column will show me NULL values for the division which have no employees accessing the system at that date. Why? And how to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:45:28+00:00Added an answer on June 14, 2026 at 4:45 pm

    Use count(distinct) to count the number of users, and group by to group the result on divisons and dates.

    You can use convert to get the date as a string from the datetime, but be aware that it slows down the query a bit.

    select d.DivisionShortcut, convert(varchar(10),l.DateTimeAccessing,120), count(distinct l.Username) as Cnt
    from dbo.employee e
    inner join dbo.[Log] l on e.Username = l.Username
    inner join dbo.Divisions d on e.DivisionCode = d.SapCode
    group by d.DivisionShortcut, convert(varchar(10),l.DateTimeAccessing,120)
    

    Update:

    Here is how you can join in the dates:

    select d.DivisionShortcut, t.DateAccessing, count(distinct l.Username) as Cnt
    from dbo.employee e
    inner join dbo.[Log] l on e.Username = l.Username
    inner join dbo.Divisions d on e.DivisionCode = d.SapCode
    inner join (
      select distinct convert(varchar(10),DateTimeAccessing,120) as DateAccessing
      from dbo.Divisions
    ) t on t.DateAccessing = convert(varchar(10),l.DateTimeAccessing,120)
    group by d.DivisionShortcut, t.DateAccessing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new developer in ASP.NET with C#. I developed an intranet web-based
I have developed one asp.net web application and now i would like to add
I am a new ASP.NET developer and I am developing a web-based suggestions box
In the web-based application developed by ASP.NET with C#, an image sent to all
I created a new ASP.NET website using Visual Web Developer 2008 Express edition and
I need to develop a mailing system in the intranet web-based application that I
I've developed a Web application in ASP.net web Forms (.net v4.0) which uses the
I have developed an ASP.NET web application in Visual Studio 2008. I have an
We are using IIS7 to host an asp.net web-based application. In this environment administrators
I have developed a web application in asp.net, there is a page in this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.