Solved

sql udpate

Posted on 2011-03-03
4
773 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
[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
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 41

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

734 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