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 7789969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:27:09+00:00 2026-06-01T21:27:09+00:00

The Setup I’m using a SQL Server DB to track various cases in production

  • 0

The Setup

I’m using a SQL Server DB to track various cases in production at a manufacturing environment. The database has two tables:

  1. Status Table: this tracks the status of those cases, with one of the columns containing an integer code that represents the cases status. All cases with codes greater than 0 are "in production" while those with codes less than or equal to 0 are either "complete" or "canceled".
  2. Log Table: this tracks what changes have happened to a particular case and when those changes happened. The "what" aspect is captured both as a string and as a code. The "when" is a datetime field.

The Problem / Task / Question

I would like to query all cases that are in production AND any cases that have been completed or canceled within the past two days. In the log, I have a datetime column and a code specific to both cancelling or completing a case. I assume the query would maybe JOIN any cases from the log that have either of those codes and have datetimes within 48 hours prior of now. But I’m not quite sure how to go about doing this. The first part of my query (to get cases that are in production) is as follows:

SELECT * FROM test.dbo.status WHERE status > 0

Any help would be greatly appreciated. Thanks in advance!

UPDATE
To clarify, two things:

  1. I would like the query to return all of the columns in the status table for records that match the criteria above, not just the ID or something.

  2. The table structures:

    CREATE TABLE [dbo].[status](
        [serial] [varchar](10) NOT NULL,
        [type] [varchar](50) NULL,
        [commit_date] [date] NULL,
        [sent_to_prod] [date] NULL,
        [target] [date] NULL,
        [sent_to_mfg] [date] NULL,
        [status] [int] NULL,
        [notes] [bit] NULL,
        [hold] [bit] NULL,
        [canceled] [bit] NULL,
        [priority] [bit] NULL,
        [vendors] [varchar](150) NULL,
        [rework] [varchar](50) NULL,
        [created_on] [datetime] NULL,
        [modified_on] [datetime] NULL
    )
    
    CREATE TABLE [dbo].[log](
        [serial] [varchar](13) NOT NULL,
        [action] [varchar](200) NOT NULL,
        [who] [varchar](80) NOT NULL,
        [time] [datetime] NOT NULL,
        [code] [varchar](20) NOT NULL
    )
    
  • 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-01T21:27:11+00:00Added an answer on June 1, 2026 at 9:27 pm

    Given you didn’t provide any structure, I’d start with something like.

    Query 1: number of records returned will be the number of matching records from LogTable

    SELECT StatusTable.ID, LogTable.When, etc etc etc.
    FROM StatusTable INNER JOIN LogTable
      ON StatusTable.ID = LogTable.ID
    WHERE StatusTable.status > 0
      OR (LogTable.WhatCode = 97   --Assumes 97 is your desired code.
      AND LogTable.When >= dateadd(hh, -48, GetDate()))
    

    Added

    Query 2: Use a sub query instead of a join to get desired IDs from LogTable. (you could also look at the EXISTS operator instead of IN)

    SELECT StatusTable.ID, StatusTable.otherField, etc etc
    FROM StatusTable
    WHERE StatusTable.status > 0 
      OR StatusTable.ID IN (SELECT LogTable.ID FROM LogTable WHERE LogTable.WhatCode = 97   --Assumes 97 is your desired code.
          AND LogTable.When >= dateadd(hh, -48, GetDate()))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Setup: Contact database using 4 tables Contacts Cities States Zips Structure: CREATE TABLE `contacts`
Setup: Windows Server 2003 / SQL Server 2005. ASP.NET 2.0. IIS 6. The site
Setup: IIS on Windows 2008 Server R2 Enterprise, SQL Server 2008 R2 Enterprise, ASP.NET
I setup a site on a new server using Plesk and I'm using site
Setup is following: Drupal project, one svn repo with trunk/qa/production-ready branches, vhosts for every
SETUP : I have this app which has 4 activities in a linear path,
Setup TFS 2010 on a pretty oldish server (actually an oldish desktop machine running
Setup I am using Sparx Systems Enterprise Architect Professional edition 7.5 and MS PowerPoint.
Setup: I have two views that I need to respond to the touch event,
Setup: ASP.net 3.5, Linq-to-Sql. Separate Web and DB servers (each 8-core, 8GB RAM). 4

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.