Skip to content

Tag: sql

IF when zero result from another Stored Procedure

I have a Stored Procedure which contains an Insert statement on it. From the above Stored Procedure, I want to have a condition from result of another Stored Procedure. With the following action: So, if cBranch is zero. Then execute Sp1 else do nothing. Need advice please. Really appreciated. Answer Try This:

How to fetch the the second row

I have a query below which is used to make a view. This query pulls the latest record of the report_id. One report_id can have multiple unique report_info_id This results in data something like Lets take the example of last record where report_id= 130 Now it is required that in first query I want such data if…

Update columns based on calculation

My table looks like this: I have a list of id’s connected to datestamps. I can manage to calculate the difference between their latest and first entry as follows: However, I am unsure how I can update my table to reflect these calculations. What I want is the following: Answer In MySQL, you can self-joi…

Create a table in a trigger and compare it

i have 4 tables and i want to create a trigger that it declares a table and store it all in that table so it can be compared latter. In here are the tables that im using. But now i have a trigger that after insert on orders it inserts on transactions. My objective now its to create a trigger