Gerald Taonah Mushamba Gerald Taonah Mushamba - 1 year ago 69
SQL Question

SQL View to join two tables that have no link

I need help I have a table "Period"

with PeriodID, fromDate, ToDate.... Then i have another one called "Transaction"

with txId, txDate, Debit, Credit... these tables are ready made for a certain program and i cant change them.

So i want to know if there is a way to Search the period table using the txDate from Transaction, then if the txDate is Between the fromDate and toDate of a certain Period i want a view that combines the Transaction take and Just Adds The PeriodID.

Answer Source

Without sample data, it is always a little hard to answer these questions. But assuming I've correctly understood you...

You can use between to join these two tables.

This join will return the period that covers the transaction date.

-- Join without a matching field.
    [Transaction] AS t
        INNER JOIN [Period] AS p        ON t.txDate BETWEEN p.fromDate AND p.toDate
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download