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
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
);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.