Solved

update stored procedure SQL server

Posted on 2009-05-13
2
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 41

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 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