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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:37:57+00:00 2026-06-02T16:37:57+00:00

I have three tables that contain data relating to a Job. One table is

  • 0

I have three tables that contain data relating to a Job. One table is a master table and the other two are transactional and are related to the master.

CREATE TABLE Job
(JobNo varchar(10))

CREATE TABLE Trans1
(JobNo varchar(10), TrxDate datetime, TrxStatus int)

CREATE TABLE Trans2
(JobNo varchar(10), TrxDate datetime, TrxStatus int)

The Job table will always have one row per job. Trans1 and Trans2 will have none, one or many rows per job.

I need to be able to write a query that will return, for a given job, what the TrxStatus column’s value was on a given date.

Let’s say Trans1 has

Job     TrxDate    TrxStatus
AB123   2/1/2012     10
AB123   3/1/2012     20
AB123   3/31/2021    20

Let’s say Trans2 has

Job    TrxDate   TrxStatus
AB123  3/15/2012   10

I need to be able to create a function (or have a solution) where I can query:

SELECT JobNo, GetStatusAt(JobNo, '3/1/2012') FROM Job

and have it return 20.

SELECT JobNo, GetStatusAt(JobNo, '3/17/2012') FROM Job

and have it return 10.

SELECT JobNo, GetStatusAt(JobNo, '4/1/2012') FROM Job

and have it return 20.

  • 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-02T16:37:59+00:00Added an answer on June 2, 2026 at 4:37 pm
    SELECT  TOP 1
            trxStatus
    FROM    (
            (
            SELECT  TOP 1
                    *
            FROM    trans1
            WHERE   jobNo = @job
                    AND trxDate <= @trxDate
            ORDER BY
                    trxDate DESC
            )
            UNION ALL
            (
            SELECT  TOP 1
                    *
            FROM    trans2
            WHERE   jobNo = @job
                    AND trxDate <= @trxDate
            ORDER BY
                    trxDate DESC
            )
            ) q
    ORDER BY
            trxDate DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that contain data from different temperature sensors: Table1 _TimeStamp Temperature
I have a MySQL query that: gets data from three tables linked by unique
I have a Microsoft SQL Server 2008 query that returns data from three tables
I have a table in my data base that has three columns: Screen, Icon,
I have a common database joining situation involving three tables. One table, A, is
I have imported data relating to about 70 human subjects from three data tables
I have 3 tables that are unrelated (related that each contains data for a
I have a POCO class, mapping to a table that basically contain three primary
Lets say that I have three tables, customers, orders and orderDetails. I'm doing this:
I have a table that has three different date columns, so I set each

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.