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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:15:44+00:00 2026-06-18T03:15:44+00:00

Hi I am a bit stuck here. I am trying to create 3 labels

  • 0

Hi I am a bit stuck here. I am trying to create 3 labels for a contract called “Green”,”Yellow”, and “Red”. The labels are identified by the formula contractdate-curdate().
– Green if it is more than 90 days away.
– Yellow – if the = end date is between 31 and 89 days
– Red if the end date is 30 days or less

I need a way to either create a column for Label and put each contract in their respective color, or create 3 columns for each color with an identifier?

These are a couple queries i’ve made but with no luck.

select 
    contractname, contractenddate
from
    contract
where
    contractenddate between CurDate() and Date_Add(CurDate(), INTERVAL 30 DAY)
        and contractenddate between CurDate() and Date_Add(CurDate(), INTERVAL 60 DAY)
and contractenddate between CurDate() and Date_Add(CurDate(), INTERVAL 90 DAY)

and

select contractname, date_sub(contractenddate,interval 0-30 day)as Red,
date_sub(contractenddate,interval 31-89 day)as Yellow,
date_sub(contractenddate,interval 90 day)as Green
 from contract

I know these are incorrect but perhaps someone could help build on these? It would be GREATLY appreicated!!! One last note is I am unable to alter the database structure, I can only use select statements.

Thanks a TON in advance!

  • 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-18T03:15:45+00:00Added an answer on June 18, 2026 at 3:15 am

    Something like this work? Look into using DATEDIFF and CASE:

    SELECT contractname, 
      contractenddate,
      CASE
          WHEN DATEDIFF(CurDate(),contractenddate) <= 30 THEN 'Red'
          WHEN DATEDIFF(CurDate(),contractenddate) < 90 THEN 'Yellow'
          ELSE 'Green'
      END Label
    FROM Contract
    

    Here is the SQL Fiddle.

    And if you want the number of days away, you could add the following to your SQL Statement:

    DATEDIFF(CurDate(),contractenddate) DaysAway
    

    Alternatively, if you need Red, Yellow and Green as Columns, something very similar would work:

    SELECT contractname, 
      contractenddate,
      CASE WHEN DATEDIFF(CurDate(),contractenddate) <= 30 THEN 'X' ELSE '' END 'Red',
      CASE WHEN DATEDIFF(CurDate(),contractenddate) < 90 AND DATEDIFF(CurDate(),contractenddate) > 30 THEN 'X' ELSE '' END 'Yellow',
      CASE WHEN DATEDIFF(CurDate(),contractenddate) >= 90 THEN 'X' ELSE '' END 'Green'
    FROM Contract
    

    I’ve put an ‘X’ to mark which have which. Wasn’t quite clear what you were looking for.

    More fiddle.

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit stuck here, basically I'm trying to compile Box2D as a static
I'm trying to create a custom search but getting stuck. What I want is
I'm a bit stuck trying to get box2D to compile and I think it's
Hey guys a bit stuck here. Ill first start with showing you the code.
I am very new to WPF and I am a bit stuck. I'm trying
So I've been trying to create a bit of code that sends data on
I'm stuck with trying to create a function that will do the following: let
I am trying to create a simple hello world example using swapcontext() Here is
I'm a bit stuck trying to loop through a table row, calculate the values
I'm a bit stuck trying to figure out how to design an Oracle query,

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.