spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Conditional update and delete based on other rows


How about first deleting all values of 11111 where there is a vendor 99999. Then do the updating on values and rows.

delete t from replenish_vendor t
    where vendor_code = 111111 and
          exists (select 1 from replenish_vendor
t2 where t2.item_code = t.item_code and
t2.vendor_code = 99999);

update replenish_vendor t
    set vendor_code = 99999,
        primary_vendor = 'F'
    where vendor_code = 111111;

Your text suggests that you want the primary vendor to be set of F in this case. The first delete might need to take into account the primary_vendor.

If you have any possibility of other database manipulations happening on the database, you should wrap these in a single transaction, so other transactions will not interfere with the data.


Categories : SQL

Related to : Conditional update and delete based on other rows
Is there a way of setting conditional formatting based on cell colour which has been activated by conditional formatting?
You can't test for cell colour in a formulas without vba. Since this is for charity , if you want I will personally help you out with excel - you can contact me directly at stevenmartin99@gmail.com

Categories : Excel
Delete line from xml based on condition
You need to load the XML into either XMLElement or a Java object(using JAXB or other lib). If using XMLEement then you will be iterating through nodes and deleting as per your condition. and in case of Java Model object, just iterate through the list delete them and then persist the same Model as XML file. Go through the Java Docs :https://docs.oracle.com/javase/7/docs/api/org/w3c/dom/Element.html

Categories : Java
Eloquent ORM - update and delete not working
public function update($id){ $inputs = Input::only(array('title')); if (!$id->update($inputs)) { Session::flash('message', 'Error!'); }else{ Session::flash('message', 'success!'); } return Redirect::to('backend/season'); } public function destroy($id){ if($id){ if($id->delete()){ Session::flash('message', 'Success: Deleted!');

Categories : PHP
How do I see the ON DELETE and ON UPDATE for a foreign key in MySQL?
You can use the INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS table that has the following columns: CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME UNIQUE_CONSTRAINT_CATALOG UNIQUE_CONSTRAINT_SCHEMA UNIQUE_CONSTRAINT_NAME MATCH_OPTION UPDATE_RULE DELETE_RULE TABLE_NAME REFERENCED_T

Categories : Mysql
Delete and Update Row from GridView on Image Button
try this protected void grdCSRPageData_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteRow") { int rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex; grdCSRPageData.Rows.RemoveAt(rowIndex); //delete from database using (SqlConnection connection = new SqlConnectio

Categories : C#
Recently Add
If you set a field name as an Alias, can you utilize that name within SQL code?
Increment next month with dayOfTheMonth SQL sybase
Update Table Set From is not working as expected
How do I find one matching strings in two txt files
SQL help needed (oracle application express)
How to Roll Up Weekending Data in SQL
How do you call a variable (that is a list of values) in a conditional statement?
Oracle INSTR backward in Oracle SQL
SQL Server 2008 Agent jobs. Two procedures and a view
Can't create table in Oracle Developer
Trigger error "ORA-01403: no data found" when It is not fire
SQL: alternatives and substitutions for GROUPING SETS and PIVOT
Excel Vlookup too Slow
Is WHERE field IS NULL quicker than >0
BFILE error on oracle
SQL Server : Select from two tables with default value 0
Use of uninitialized value after fetchrow()
Why did this UPDATE change all rows instead of just one row?
Oracle / SQL Counting Different values from one Column and storing it in a variable
How can I calculate the percentage of occurrences of a value in a column?
To compute sum regarding to a constraint
Enterprise Architect - Execute SQL Issue
First business day of the current month - SQL Server
Incorrect no. of rows fetched in SQL
SQL query design with configurable variables
Grouping dates by dateadd and datediff
SQLServer get top 1 row from subquery
SQL Using CONTAINS() doesn't work for AND & OR
SQL Server: Persisting computed column
Improve SQL Server query
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.