I want insert record with start date end date from company table to transactions table in sql

Rajnish Pandey
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 24, 2025

I have two table in SQLserver 
Company table
Transactions table
Company table
___________________________________
CId _ Name _ StartDate _ EndDate
____|________________________________

      1      |    ABC   |     01/04/2024  | 31/03/2025

    And 2and table have 

Transactions table 


___________________________________
Tid _ Description _ Transactions date
____|________________________________

      1      |    Expense  |       |      3/01/2025

    I want to insert record when transactions table date matches from  company table  date range then Insert record 

If not match record not saved 

If  

Tid _  Description _  Transactions date 
____|________________________________

      1      |    Expense  |       |      22/01/2027

Date range not over lapping  

 

 

 

 

1 answer

0 votes
Mirek
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 28, 2025

Hello @Rajnish Pandey 

If I understand correctly maybe it would be something like this? 

INSERT INTO Transactions (Tid, Description, TransactionDate) 
SELECT 1, 'Expense', '2025-01-03'
WHERE EXISTS (
SELECT 1 FROM Company
WHERE '2025-01-03' BETWEEN StartDate AND EndDate
);

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events