Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi, i have two table t1,t2 and one target table t3

t1 have 3 columns
t2 have 3 columns (different columns)

i inserted t1,t2 tables and stored successfully
now i want to copy(column values) the all t1,t2 values in t3 table based on (t1.id=t2.id )

if t1,t2 updated means t3 automatically update this is possible.
and next i want to fetch all t3 column values in a gridview
plz help
Posted
Updated 28-Mar-13 2:37am
v2

Hi,

Try like below.
SQL
IF NOT EXISTS(SELECT OBJECT_ID('t3'))
BEGIN
    SELECT * INTO t3 from 
    (SELECT A.col1, A.col2, A.col3, A.id, B.t2Col1, B.t2Col2 
    FROM t1 A INNER join t2 B ON A.id = B.id) temp
END

select * from t3


This will create new table t3, with the columns from t1 & t2

hope it helps.
 
Share this answer
 
Comments
sreeprakash248 28-Mar-13 8:22am    
where i place this query stored procedure!!! and when t1,t2 updated means t3 default update that information.... thanks
Hi,

I think you have to do this stuff from Back-End,

execute below code in SqlServer Might helps you...

Insert Into T3
Select T1.*,T2.* from T1
Inner Join T2 on T1.Id = T2.Id
Where T1.Id is not Null or T2.Id is Not Null
And T1.ID Not In
(
Select (Name if T1.Id) From T3
)
And T2.ID not In
(
Select (Name if T2.Id) From T3
)

after that fire "select * from T3" and get result back and Bind to Grid.
 
Share this answer
 
Comments
sreeprakash248 28-Mar-13 8:40am    
plz tel im confused where i place this query... table3?

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