Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

update stored procedure SQL server

Posted on 2009-05-13
2
Medium Priority
?
257 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

610 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