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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:32:36+00:00 2026-05-14T08:32:36+00:00

I am weak in SQL and need some help working through some logic with

  • 0

I am weak in SQL and need some help working through some logic with my proc.

Three pieces: store procedure, table1, table2

Table 1 stores most recent data for specific IDs

Customer_id status_dte  status_cde    app_dte
001         2010-04-19  Y             2010-04-19

Table 2 stores history of data for specific customer IDs:
For example:

Log_id  customer_Id status_dte  status_cde
01     001         2010-04-20   N
02      001         2010-04-19   Y      
03      001         2010-04-19   N
04      001         2010-04-19   Y

The stored proecure currently throws an error if the status date from
table1 is < than app_date in table1.

If @status_dte < app_date
    Error

Note: @status_dte is a variable stored as the status_dte from table1

However, I want it to throw an error when the EARLIEST status_dte from
table 2 with a status_cde of ‘Y’ is less than the app_dte column in
table 1.

Keep in mind that this earliest date is not stored anywhere, the history
of data changes per customer. Another customer might have the following
history.

Log_id  customer_Id status_dte  status_cde
01     002         2010-04-20  N
02      002         2010-04-18  N       
03      002         2010-04-19  Y
04      002         2010-04-19  Y

Any ideas on how I can approach this?

  • 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-14T08:32:36+00:00Added an answer on May 14, 2026 at 8:32 am

    You can test in one go per customer to find where the earliest date is less than the appdate using this construct

    IF EXISTS (SELECT *
        FROM
          mytable M
          JOIN
          HistoryTable H ON M.customer_Id = H.customer_Id
        WHERE
          H.status_cde = 'Y'
        GROUP BY
          H.customer_Id, M.app_dte
        HAVING
         MIN(H.status_dte) < M.app_dte)
      ...error...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store weak references to objects in an NSArray, in order to
I am very weak with Regex and need help. Input looks like the following:
Weak as in weak references. Basically, I need a sequence of numbers where some
My Google-Fu is weak today, hopefully this is a simple thing. I need to
My knowledge of regular expression is very weak. I am needing help building the
Please recommend me some books and practices for me. I am quite weak in
I'm working in J2EE web project, which has lots of Java, SQL scripts, JS,
SQL is my weak part, however I can handle it. I was wondering if
My SQL-fu is too weak for this, and I'm not even sure it's possible
Being weak on regular expressions, I've been working with them to improve. One concept

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.