question

Malaika avatar image
Malaika asked

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.
insertsubquery
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

What do you have so far?
0 Likes 0 ·

1 Answer

·
VishalhSingh avatar image
VishalhSingh answered
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)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.