Click here to Skip to main content
15,912,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Expect,


Need to update a table with the fields content from another in the back-end in ms sql server 2008.


Using New Query tool


The 2 tables are as follows.


The table to be updated is :


Table_Update.dbo

1. Idno
2. Name
3. Update_Amount


The table from which the data is coming from is

Table_From

1. Idno
2. Name
3. From_Amount

Please provide me with a routine to carry out the above in the backend


Thanks

What I have tried:

Checked the internet but couldn't find a sample
Posted
Updated 26-Feb-16 20:01pm
v2

1 solution

Try this - See the UPDATE query below

SQL
CREATE TABLE DstTbl (Idno INT,Name NVARCHAR(50),Update_Amount INT)
CREATE TABLE SrcTbl (Idno INT,Name NVARCHAR(50),Update_Amount INT)

INSERT INTO SrcTbl 
SELECT 1,'AB',100

INSERT INTO DstTbl 
SELECT 1,'',null

UPDATE DstTbl SET Name=s.Name, Update_Amount =s.Update_Amount 
FROM SrcTbl s INNER JOIN DstTbl d on s.Idno=d.Idno

select * from DstTbl
 
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