Solved

update stored procedure SQL server

Posted on 2009-05-13
2
211 Views
Last Modified: 2012-05-06
Hi,
 I have table called tbl1 contain 3 fields f1, f2, Y
I need help to write stored procedure which goes over each row in table (tbl1)
then update tbl2
update tbl2 set tbl2.Y2 = tbl1.Y WHERE tbl2.f1 = tbl1.f1 AND tbl2.f2 = tbl1.f2

tables fields
tbl1                 tbl2
f1,f2,Y             x,y,z,f1,f2,Y


Thanks
0
Comment
Question by:madmare
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 24374336
Hello madmare,

update t2
set Y2 = t1.Y
FROM tbl2 t2
INNER JOIN tbl1 t1
on t2.f1 = t1.f1 AND t2.f2 = t1.f2

Regards,

Aneesh
0
 
LVL 40

Expert Comment

by:Sharath
ID: 24375840
if you need a stored proc for this, try like the attached.
Invoke the SP as,
exec sp_YourProc

create procedure sp_YourProc as

update t2 

set Y2 = t1.Y 

FROM tbl2 t2

INNER JOIN tbl1 t1 

on t2.f1 = t1.f1 AND t2.f2 = t1.f2

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now