May 27, 2009 at 3:28 pm
I have 2 tables; tbl1 and tbl2.
Information:
tbl1 has the following columns;
PID, PNUM, PDISC
tbl2 has the following columns;
PID, PNUMR, PDISCR. COlumn 'PID' has NULL values all the way across.
I need help with TSQL that will populate Column 'PID'in tbl2 from Column 'PID' in tbl1. Only thing that
matches between two tables are columns 'PNUM' and 'PNUMR'. That is column PNUM in tbl1 = column PNUMR in tbl2.
I am new to TSQL. Pleaes help! Thanks!!
May 27, 2009 at 4:11 pm
Hi,
You’ll need an update statement, something like:
UPDATE tbl2
SET PID = tbl1.PID
FROM tbl1
WHERE PNUMR = tbl1.PNUM
Allister
May 27, 2009 at 5:32 pm
Thank you SSC Rookie...that worked like a charm!!
April 23, 2012 at 12:29 am
Could yu guide me on how I could do the above automated, every time, a data entry goes into oen tabe, how can I get it to move into the other one?
April 23, 2012 at 2:07 am
Create an AFTER INSERT trigger and add that query into it.
======================================
Blog: www.irohitable.com
April 23, 2012 at 2:08 am
Grasshopper,
Could you please elaborate a little more, since I am relatively new to this.
Thanks in advance
April 23, 2012 at 3:54 am
A trigger is similar to stored procedures with a little difference. Trigger is attached to a table and the code gets executed automatically when row is inserted, updated or deleted from the table.
There are very good tutorials available. Below are few links:
How To: SQL Server Trigger 101[/url]
======================================
Blog: www.irohitable.com
April 23, 2012 at 5:10 am
Thankyou very much I shall go through them and get back if I get stuk again. Thanks a lot
So, if I want to move all messages coming from Service ID = 200 from Table_MessagesOut to Table_MessagesIn Service ID 202, the sql command would be the same as above right?
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply