Sql server: Insert multiple tables data into another table

In this article I am going to explain how to insert multiple tables data into one table in sql server.


Implementations:
I have created 2 tables Country and state, insert some dummy records into it. I want to insert country and state name into another table (countrystate).

Tb_Country
Id
int
CountryName
varchar(100)

Tb_State
Id
int
StateName
varchar(100)
CountryId_Fk
int

CountryState
CSId
int
Country
varchar(200)
Statename
varchar(200)
Recdate
date


Get the date from both table using join and insert into table.

Insert into CountryState(Country,Statename)
SELECT     dbo.Tb_State.StateName, dbo.Tb_Country.CountryName
FROM         dbo.Tb_Country INNER JOIN
                      dbo.Tb_State ON dbo.Tb_Country.Id = dbo.Tb_State.CountryId_Fk



Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget