473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help needed with update

Hi,
i just need to write a stored proc which sums the salary (from abc table) by id
and the total must be written to NetSalary(deftable)
here is the sample data....

create table abc (id varchar (10), salary decimal)

insert into abc values ('10001', 26150.98)
insert into abc values ('10002', 26150.98)
insert into abc values ('10001', 1124.00)
insert into abc values ('10001', 345.98)
insert into abc values ('10002', 6547.90)
insert into abc values ('10003', 6548.88)

create table def (id varchar (10), NetSalary decimal)

insert into def values('10001',null)
insert into def values('10002',null)
insert into def values('10003',null)

this is what i tried...
create proc sp_xyz
as
begin
select sum (salary) As sumofsalary from abc
group by id
end
--exec sp_xyz

now iam not able to understand how to update the total in the netsalary column of def table.......
i think i need to write an update for this but i am not able to figure it out how to write...
can anyone help me with the above probs plz???
thanks,
raaj
Jan 28 '08 #1
2 1097
ck9663
2,878 Expert 2GB
Hi,
i just need to write a stored proc which sums the salary (from abc table) by id
and the total must be written to NetSalary(deftable)
here is the sample data....

create table abc (id varchar (10), salary decimal)

insert into abc values ('10001', 26150.98)
insert into abc values ('10002', 26150.98)
insert into abc values ('10001', 1124.00)
insert into abc values ('10001', 345.98)
insert into abc values ('10002', 6547.90)
insert into abc values ('10003', 6548.88)

create table def (id varchar (10), NetSalary decimal)

insert into def values('10001',null)
insert into def values('10002',null)
insert into def values('10003',null)

this is what i tried...
create proc sp_xyz
as
begin
select sum (salary) As sumofsalary from abc
group by id
end
--exec sp_xyz

now iam not able to understand how to update the total in the netsalary column of def table.......
i think i need to write an update for this but i am not able to figure it out how to write...
can anyone help me with the above probs plz???
thanks,
raaj
option 1:
if you will create def table from abc table, why not just use a SELECT...INTO... something like...

select id, sum(salary) as NetSalary into def from abc group by id

option 2:
if you have an existing def table and you need the update...try something like

Expand|Select|Wrap|Line Numbers
  1. UPDATE abc
  2. set NetSalary = TotalSalary
  3. from (select id, sum(salary) as TotalSalary into def from abc group by id) SummaryTable
  4. where SummaryTable.id = abc.id
  5.  

-- CK
Jan 28 '08 #2
yep...i got it...
thnx for ur reply...
Jan 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
5
by: Hexman | last post by:
I've come up with an error which the solution eludes me. I get the error: >An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in HRTest.exe > >Additional...
2
by: Steve K | last post by:
I got a bit of a problem I like some help on. I'm designing an online training module for people that work in food processing plants. This is my target audience. These workers have little or no...
1
by: Alexandre CONRAD | last post by:
Hello list ! I'm using the ConfigParser module to use configuration files (what else would it be for ?). But I have a dilema: I'd like to setup multiple "update server" for my application with...
2
by: Hexman | last post by:
Hello All, Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in my update statement and when trying...
1
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.