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

x
?
Solved

sql udpate

Posted on 2011-03-03
4
Medium Priority
?
779 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 1000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

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