Solved

update stored procedure SQL server

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to run sql statements from SQLCMD or command line 2 66
How to query LOCK_ESCALATION 4 41
View SQL 2005 Job package 16 70
SQL Server 2005 - Comparing Fields' Contents 6 44
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 article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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