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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:54:28+00:00 2026-05-26T03:54:28+00:00

Looking to use the following data and populate the datetime in status table only

  • 0

Looking to use the following data and populate the datetime in status table only if status =
‘D’ and there is NOT another record with the same transaction_id that has a status <> ‘D’, if the ‘D’ record is the selected record, we also want the datetime of the first ‘D’ record.

DECLARE decision TABLE (
transaction_id NCHAR(1),      
event_id INT,      
status NCHAR(1) NULL,
statud_date datetime
)  

INSERT decision VALUES     
( '1' , 1 , 'D', '2011-01-01'),     
( '1' , 2 , 'D', '2011-01-01'),     
( '1' , 3 , 'A', '2011-01-01'),     
( '2' , 1 , 'D', '2011-05-01'),     
( '2' , 2 , 'D', '2011-05-02'),  
( '2' , 3 , 'D', '2011-05-03'),     
( '3' , 1 , 'D', '2011-05-05'),     
( '3' , 2 , 'A', '2011-05-06'),     
( '3' , 3 , 'C', '2011-05-06'),
( '4' , 1 , 'D', '2011-10-01')


DECLARE status TABLE (
transaction_id NCHAR(1),      
default_dt datetime
)

INSERT load VALUES     
( '1' , NULL ),     
( '2' , NULL ),     
( '3' , NULL ),
( '4' , NULL )     

Looking to get this result:

1   NULL
2   2011-05-01
3   NULL
4   2011-10-01
  • 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-26T03:54:28+00:00Added an answer on May 26, 2026 at 3:54 am

    If I understand you correct tnan you can look at this:

    DECLARE @decision TABLE (
    transaction_id NCHAR(1),      
    event_id INT,      
    status NCHAR(1) NULL,
    status_date datetime
    )  
    
    INSERT @decision VALUES     
    ( '1' , 1 , 'D', '2011-01-01'),     
    ( '1' , 2 , 'D', '2011-01-01'),     
    ( '1' , 3 , 'A', '2011-01-01'),     
    ( '2' , 1 , 'D', '2011-05-01'),     
    ( '2' , 2 , 'D', '2011-05-02'),  
    ( '2' , 3 , 'D', '2011-05-03'),     
    ( '3' , 1 , 'D', '2011-05-05'),     
    ( '3' , 2 , 'A', '2011-05-06'),     
    ( '3' , 3 , 'C', '2011-05-06'),
    ( '4' , 1 , 'D', '2011-10-01')
    
    
    DECLARE @status TABLE (
    transaction_id NCHAR(1),      
    default_dt datetime
    )
    
    INSERT @status VALUES     
    ( '1' , NULL ),     
    ( '2' , NULL ),     
    ( '3' , NULL ),
    ( '4' , NULL )
    
    
    --1st approach
    UPDATE S
    SET S.default_dt=D.status_date
    FROM @status S
         JOIN (SELECT transaction_id,MIN(status_date) status_date, COUNT(*) cnt
               FROM @decision
               WHERE [status]='D'
               GROUP BY transaction_id) D ON S.transaction_id=D.transaction_id
    WHERE S.transaction_id NOT IN (SELECT transaction_id FROM @decision WHERE [status]<>'D')
    
    SELECT * FROM @status       
    
    --2nd approach  
    UPDATE S
    SET S.default_dt=D.status_date
    FROM @status S
         JOIN (SELECT transaction_id,MIN(status_date) status_date, COUNT(*) cnt
               FROM @decision
               WHERE [status]='D'
               GROUP BY transaction_id) D ON S.transaction_id=D.transaction_id
         JOIN (SELECT transaction_id, COUNT(*) cnt
               FROM @decision
               GROUP BY transaction_id) D2 ON S.transaction_id=D2.transaction_id AND D.cnt=D2.cnt
    
    SELECT * FROM @status   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to use quartz to schedule emails, but I'm not sure which
So in looking through Core Data Snippets , I found the following code: ...
I'm looking to get a count for the following data frame: > Santa Believe
I am looking for a way to only insert when the row does not
Without going into too much detail we are looking to use XML as meta-data
I'm looking for a data structure that has the following properties. Stores a list
i want to use a matrix type data structure for storing and looking up
I am looking to use a PHP library for uploading pictures to a web
We are looking to use the MVC Framework in our SP Application. This is
I'm looking to use procedurally-generated sound and music in a Flash program I'm writing.

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.