Solved

sql udpate

Posted on 2011-03-03
4
767 Views
Last Modified: 2012-05-11
I have two tables named issue and stock. I want to delete record from issue table and update stock table if only the partno from stock table exists in the issue table. how can write a single sql statment? Also how can write 'success' and ' fail' for delete and update respectively?

partno storeid    stock
p101    sh            100
p101    ws            50

issue
id  partno  qty  storeid
p  101      10    sh

thanks

ayha
0
Comment
Question by:ayha1999
4 Comments
 
LVL 15

Expert Comment

by:Aaron Shilo
ID: 35030891
this should get you started

begin

delete from issue where partno  =101

update stock table set column = value
where partno = (select partno from deleted)

end
0
 
LVL 40

Accepted Solution

by:
Sharath earned 250 total points
ID: 35032062
You need two statements, One for UPDATE and another for DELETE. You can try like this. Where do you want to write 'Success' and 'Failure' messages?
Do you want to log it somewhere?
update s
   set s.stock = i.qty
  from stock s
  join issue i on s.storeid = i.storeid
delete from issue 

Open in new window

0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 35032485
you can't have 1 sql statement do what you are asking...

the closest you could come is to put all the code required into a stored procedure
which you could the perform as 1 statement....

please be more specific about your requirements...

what does if only the partno from stock table exists in the issue table mean
and Also how can write 'success' and ' fail' for delete and update respectively?  
what do you mean by write and where do you want it published?
0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 35057108
thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

920 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

16 Experts available now in Live!

Get 1:1 Help Now