Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have to fetch some data (e.g. Email, ClientName, DOB, CNIC, ClientId) of the clients who's birthday lies on current date for some purpose, and then log/insert it into a new table "Birthday_Client". But i am getting difficulty in making query because of DB structure it is like this:

DB-1 has tables Account and Client
Account table has Email, CNIC and ClientID
&
Client table has ClientName

DB-2 has table Client_Detail
Client_Detail has DOB(i.e. date of birth)


so i have to fetch the data of only those clients who's birthday is on current date and then insert this selected data into a new table viz Birthday_Client.
Please help!

P.S. : For making things easy for you ClientID column is present in all the tables.
Posted
Comments
Thomas Nielsen - getCore 1-Oct-14 8:56am    
Does DB-1 and DB-2 refer to these data being in different databases?
Is it relevant if the query is performend in SQL server (TSQL) or using .net for instance?

Sounds like you need a join between the two client tables and then insert the information into a third table.

You can use something like
insert into Birthday_Client (fieldname 1, fieldname2 etc) select fieldname 1, fieldname2 etc from db-1 inner join db-2 on db-1.ClientID = db-2.ClientID where db-2.DOB = getdate()


You may need to be careful about the dob field. If it includes time then you may need to expand the query so that it is between the start and end of the day.
 
Share this answer
 
SQL
You can use something like

insert into Clients_Birthday
(clientId) select db-1.ClientIDfrom db-1 inner join db-2 on db-1.ClientID = db-2.ClientID
 where  DATEPART(d, db-2.DOB= DATEPART(d, GETDATE())
    AND DATEPART(m, db-2.DOB= DATEPART(m, GETDATE())
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900