Solved

update stored procedure SQL server

Posted on 2009-05-13
2
221 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

19 Experts available now in Live!

Get 1:1 Help Now