Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
after insert update from another table
after insert update from another table
Rate Topic
Display Mode
Topic Options
Author
Message
cts_account
cts_account
Posted Monday, February 18, 2013 5:05 PM
Forum Newbie
Group: General Forum Members
Last Login: Tuesday, February 19, 2013 9:29 AM
Points: 1,
Visits: 7
newbie here...can't seem to get this to function properly, tried creating many variants of standalone triggers and triggers calling a stored procedure passing variables. During testing, all of the records in one table get updated instead of only one. Here's my scenario in MSSQL2008:
table1 with 5 columns, column1 is primary key int, col(2,3,4 & 5) are varchar(25)
table2 has the exact same columns
when a record is inserted into table1,
1)lookup the matching record in table2 where the datavalue in table1.column2 = datavalue in table2.column2
2)then update columns 3, 4 & 5 in the inserted record (table1) with the data from result set from their matching columns in table2, ie. where table1.3=table2.3, table1.4=table2.4, table1.5=table2.5;
3)only use the newest record in table2
4)only update the newly inserted record
Any help would be great, thanks.
Post #1421381
bitbucket-25253
bitbucket-25253
Posted Monday, February 18, 2013 6:59 PM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 9:02 PM
Points: 5,100,
Visits: 20,195
Believe what you may be looking for is the MERGE statement. For a discussion and example of how it works:
http://www.simple-talk.com/sql/learn-sql-server/the-merge-statement-in-sql-server-2008/
If you would/could post the table definition, some sample data and desired result someone may be able to assist you with tested sample T-SQL.
To provide the sample as I suggested please click on the first link in my signature block and read the article. The article has sample T-SQL to allow you to post the table definition, some sample data and desired result simply and easily.
If everything seems to be going well, you have obviously overlooked something.
Ron
Please help us, help you -before posting a question please
read
Before posting a performance problem please
read
Post #1421403
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.