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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:48:03+00:00 2026-05-26T14:48:03+00:00

I am working on a calculated column that will return an X if specific

  • 0

I am working on a calculated column that will return an “X” if specific criteria are met. The criteria are based pm three columns. The table actually has several columns.

COLUMN1     COLUMN2     COLUMN3     DATE
1234          100         300       1/1/2002
2245          100         500       2/3/2002   
1234          400         400       4/5/2007
2256          100         500       7/5/2010
1234         

The calcucated column will return and x if COLUMN1 has a value of 1234 OR IF COLUMN2 has 2 consecutive values < 200 within a 2 year period or COLUMN3 has 2 consecutive values > 300 within a 2 year period

According to this criteria row 1,3, and 5 will return an X due to the number 1234.
According to Column 2 row 1 will return an X due to the fact that there was a value less then 200 twice in a row within a 2 year period..

Any help would be greatly appreciated….

  • 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-26T14:48:04+00:00Added an answer on May 26, 2026 at 2:48 pm

    This might be quite slow on larger volumes of data due to the self join, but should provide you with the data you are looking for…

    CREATE TABLE #data
    (column1 INT
    ,column2 INT
    ,column3 INT
    ,column4 DATETIME)
    INSERT INTO #data 
    SELECT 1234         , 100    ,     300     ,'1/1/2002' UNION ALL
    SELECT 2245        ,  100    ,     500     ,'2/3/2002'  UNION ALL
    SELECT  1234      ,    400   ,      400     ,' 4/5/2007' UNION ALL
    SELECT 2256      ,    100    ,     500      ,'7/5/2010' UNION ALL
    SELECT 1234     , NULL,NULL,NULL
    
    ;with CTE AS
    (
    SELECT * 
    ,row_number() OVER (ORDER BY CASE WHEN column4 IS NULL THEN 0 ELSE 1 END DESC) as row
    FROM #data
    )
    SELECT DISTINCT 
    c1.row
    ,c1.column1
    ,c1.column2
    ,c1.column3
    ,c1.column4
    ,CASE WHEN DATEDIFF(YY,c1.column4,c2.column4) < 2 AND c1.column2 < 200 AND c2.column2 < 200 THEN 'X'
            WHEN c1.column1 = 1234 THEN 'X'
            WHEN DATEDIFF(YY,c1.column4,c2.column4) < 2 AND c1.column3 > 300 AND c2.column3 > 300 THEN 'X' 
            END AS column5
    FROM CTE c1
    LEFT OUTER JOIN CTE c2
    ON c1.row + 1 = c2.row 
    ORDER BY c1.row ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way of working with calculated fields of Propel objects? Say
I'm currently working on a class that calculates the difference between two objects. I'm
I'm working on a program that asks for input, then calculates and posts the
I am working on a calculator that allows you to perform calculations past the
I'm working on a script that generate some Excel documents and I need to
I have been working on creating a kpi that compares the rank of a
I am working on an application that needs to handle expiring airline miles. The
I am working on a small project that generates SQL queries from a list
Hey guys, I'm working on a program for a university course that uses a
Bit of a strange problem here... I've got an update query that isn't working,

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.