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

  • SEARCH
  • Home
  • 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 5967931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:00:57+00:00 2026-05-22T20:00:57+00:00

I have another rather curious problem. I have the following structure: CREATE TABLE [dbo].[Event]

  • 0

I have another rather curious problem. I have the following structure:

CREATE TABLE [dbo].[Event]
(
    Id int IDENTITY(1,1) NOT NULL,
    ApplicationId nvarchar(32) NOT NULL,
    Name nvarchar(128) NOT NULL,
    Description nvarchar(256) NULL,
    Date nvarchar(16) NOT NULL,
    Time nvarchar(16) NOT NULL,
    EventType nvarchar(16) NOT NULL,
    SourceId int NOT NULL,
    CONSTRAINT Event_PK PRIMARY KEY CLUSTERED ( Id ) WITH (
        PAD_INDEX = OFF, 
        STATISTICS_NORECOMPUTE = OFF, 
        IGNORE_DUP_KEY = OFF, 
        ALLOW_ROW_LOCKS = ON, 
        ALLOW_PAGE_LOCKS  = ON
    ),
    CONSTRAINT Event_Source FOREIGN KEY (SourceId) REFERENCES [dbo].[Source](Id)
)

CREATE TABLE [dbo].[Source]
(
    Id int IDENITY(1,1) NOT NULL,
    Name nvarchar(128) NOT NULL,
    Description nvarchar(256) NULL,
    CONSTRAINT Source_PK PRIMARY KEY CLUSTERED ( Id ) WITH (
        PAD_INDEX = OFF, 
        STATISTICS_NORECOMPUTE = OFF, 
        IGNORE_DUP_KEY = OFF, 
        ALLOW_ROW_LOCKS = ON, 
        ALLOW_PAGE_LOCKS  = ON
    )
)

The data from the event table has to be displayed in a grid. In my previous question I learned how to properly query and display the data while only displaying the last record per ApplicationId (aka… grouping it and displaying the last record for each group). (http://stackoverflow.com/questions/6201253/how-to-get-the-last-record-per-group-in-sql) Thank you @Anthony Faull, @Damien_The_Unbeliever, and all others who contributed to that answer.

Unfortunatelly a new requirement has been thrown at me and it involves the SourceId and EventType fields of this table.

Basically the new requirement states that for a specific value of in the EventType (‘APP_CLOSE’ and ‘APP_START’) column grab the Name of the source. For everything else display ‘NULL’ or some other predefined value.

I am trying to create a view that will accommodate this request and attempted using a LEFT OUTER JOIN. The problem is that some records in the Event table have values in the SourceId and I don’t the data brought by the JOIN for these records unless the EventType field is ‘APP_CLOSE’ or ‘APP_START’.

Any ideas on how to do this?

EDIT*

Since someone pointed out that I suck at explaining what the issue is I decided to do a follow up:

Event:

| Id | ApplicationId  | Name  | Description | Date       |Time     | EventType | SourceId |
+----+----------------+-------+-------------+------------+---------+-----------+----------+
|1   |2202            |XYZ    | Test        | 05/31/2011 |10:30:55 | APP_CLOSE | 2        |
+----+----------------+-------+-------------+------------+---------+-----------+----------+
|2   |2709            |zyx    | Test        | 05/31/2011 |11:27:55 | APP_START | 4        |
+----+----------------+-------+-------------+------------+---------+-----------+----------+
|3   |2709            |zyx    | Test        | 05/31/2011 |17:09:55 | APP_PAUSE | 1        |

Source Table:

| Id | Name              | Description |
+----+-------------------+-------------+
| 2  | Process Watcher   |             |
+----+-------------------+-------------+
| 4  | Interrupt Handler |             |
+----+-------------------+-------------+
| 1  | User Input        |             |
+----+-------------------+-------------+

Result (Query or View):

| Id | ApplicationId  | Name  | Description | Date       |Time     | EventType | Source Name          |
+----+----------------+-------+-------------+------------+---------+-----------+----------------------+
|1   |2202            |XYZ    | Test        | 05/31/2011 |10:30:55 | APP_CLOSE | Process Watcher      |
+----+----------------+-------+-------------+------------+---------+-----------+----------------------+
|2   |2709            |zyx    | Test        | 05/31/2011 |11:27:55 | APP_START | Interrupt Handler    |
+----+----------------+-------+-------------+------------+---------+-----------+----------------------+
|3   |2709            |zyx    | Test        | 05/31/2011 |17:09:55 | APP_PAUSE |                      |       

The idea is that even though a user can pause the app, the user is not a tangible piece of the software. Therefore when reporting on Events that have occurred I can only report on events that are caused by the components of the software. In other words I only need to bring in the Source Name based on the specific event types (APP_CLOSE and APP_START) for now.

Thanks,

Martin

  • 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-05-22T20:00:58+00:00Added an answer on May 22, 2026 at 8:00 pm
    select e.*, s.Name, ISNULL(s.Name,'Predefined Value')
    from [Event] as e
    left join [Source] as s on (s.Id = e.SourceId)
                           and (e.EventType in ('APP_CLOSE','APP_START'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey! I am not trying to push my luck here but I have another
I have code to create another row (div with inputs) on a button click.
I have a ListView inside another ListView, and I'd like to hide a table
I'm developing a Linux driver loadable module and I have to use another device
I have a situation where another developer is including source files from a project
I have a Java application that launches another java application. The launcher has a
I have a value like this: Foo Bar Another Value something else What regex
I have an application that writes to another application and needs to provide the
I have a Form being launched from another form on a different thread. Most
Put it another way: what code have you written that cannot fail. I'm interested

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.