Difficulty fetching data from two different databases using a subquery and inserting into a new table.
I have to fetch some data (Email, ClientName, DOB, CNIC, ClientId) of the clients who's birthdays lie on the current date. I must then log/insert the data into a new table called "Birthday_Client". I am getting difficulty in writing a query because of the DB structure. It is like this: DB-1 has the tables [Account] and [Client] The [Account] table has columns [Email], [CNIC] and [ClientID] The [Client] table has the [ClientName] column. DB-2 has the table [Client_Detail] The [Client_Detail] table has the [DOB] (i.e. date of birth) column. I have to fetch data of only those clients whose birthdays are on the current date and then insert this selected data into a new table, [Birthday_Client]. Please help! P.S. : The ClientID column is present in all the tables.
Did you try with full name conventions i.e. something like this: SELECT ACT.Email, CLT.ClientName, CLD.DOB, Act.CNIC, ACT.ClientId FROM DB1..Account ACT INNER JOIN DB1..Client CLT ON ACT.ClientID=CLT.ClientID INNER JOIN DB2..ClientDetail CLD ON ACT.ClientID=CLD.ClientID Once you have the recordset of what you wanted to retrieve you may later insert in the third table (using same approach i.e. full naming convention DB3..Table3). (ignore the typos or minor syntax errors as the above script was completely typed in using notepad)