Please help with multiple update [message #602009] |
Thu, 28 November 2013 14:50 |
|
envision2005
Messages: 9 Registered: November 2013
|
Junior Member |
|
|
I am trying to change the query but the request is somehow complicated:
I have a table with 3 columns:
Start date, seqID, Name
07/07/2013 1 Name1
07/09/2013 2 Name2
07/11/2013 3 Name3
07/15/2013 4 Name4
07/20/2013 5 Name5
If start date 07/15/2013 is changed to 07/10/2013 then seq ID 4 becomes 3 and the row becomes after 07/09/2013, seq ID 2
If Start Date 07/09/2013 is changed to 07/16/2013 then the row is re-sequenced as number 4 and moved to above 07/20/2013: The update would be as follows:
Start date, seqID, Name
07/07/2013 1 Name1
07/11/2013 2 Name3
07/15/2013 3 Name4
07/16/2013 4 Name2
07/20/2013 5 Name5
How can I re-sequence the seqID when start date is changed?
Thanks
|
|
|
|
|
|
|
|
Re: Please help with multiple update [message #602023 is a reply to message #602016] |
Thu, 28 November 2013 23:44 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
BlackSwan wrote on Fri, 29 November 2013 07:18You should NEVER store a computed value within a (static) row.
Every computed value should be selected, computed & displayed as needed.
True. But if it is really needed, then for 11g and up, virtual columns could be used. Although, they are some restrictions.
|
|
|
|
|
Re: Please help with multiple update [message #602099 is a reply to message #602062] |
Fri, 29 November 2013 06:58 |
|
envision2005
Messages: 9 Registered: November 2013
|
Junior Member |
|
|
I am using Oracle 11g
Will this work:
UPDATE myTable
SET seqID = (SELECT r FROM (SELECT rs1.startDate, rs1.seqID, rs1.name,
ROW_NUMBER() OVER (PARTITION BY rs1.startDate, rs1.seqID, rs1.name
ORDER BY rs1. startDate) AS r
FROM myTable rs1
WHERE rs1.startDate = :DateEntered --07/20/2013
AND rs1.seqID = 2)
WHERE rs1.startDate = startDate AND rs1.seqID = seqID AND rs1.name = name)
WHERE startDate = :DateEntered AND seqID = 2
[Updated on: Fri, 29 November 2013 07:20] Report message to a moderator
|
|
|
|
|
|
Re: Please help with multiple update [message #602173 is a reply to message #602171] |
Sat, 30 November 2013 16:26 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
Quote:Pablolee,
Please don't take it that way.
What other way should it be taken. Several posts point out that your model is flawed. You post an attempt at a solution that utterly ignores that advice that you were given. I say again, what other way should it be taken?
Quote:The replies from all above are appreciated and all agreed that the requirement is not correct. Yet, you chose to ignore that.
Quote:Again, I am not Oracle expert to that level That's why you are here, asking advice, no problem with that.
Quote:and what I got is very tricky problem. Hmmm, no, you don't. Based on your description, you have a very simple problem, easily solved by using a view, or virtual columns
Quote:No fruits to enjoy but again appreciate the replies. I'm not sure what that means, but if you're trying to say that this thread doesn't contain the answer to your problem, then either you are completely wrong, or you have completely misrepresented your problem.
|
|
|
Re: Please help with multiple update [message #602174 is a reply to message #602173] |
Sat, 30 November 2013 18:03 |
|
envision2005
Messages: 9 Registered: November 2013
|
Junior Member |
|
|
Let me try again to explain the scenario: Screen with gridView. Each row has 2 buttons: Edit & Delete
When user click "Delete" on any row, the row is deleted and the screen is refreshed at run time. Below is the Query:
Update myTable
SET PROJECT_DISPLAY_NBR = PROJECT_DISPLAY_NBR - 1,
UPDATE_DTTM = '16-AUG-2013', UPDATE_USER = 'ANY.NAME'
WHERE PROJECT_DISPLAY_NBR >= '2' AND PROJECT_SEQ_ID = 40819; --"Project_display_Nbr" 2 is row 2 which is selected to delete.
When Editing the row, user is only allowed to change the date in the row. When date is changed then 2 things I need to do: 1) Compare the date of the row changed with the dates of the rest of the rows (up & down). 2) If the date that is updated is less than the above row (for example) then the "project display nbr" is also updated.
Start date, project_Display_nbr, Name
07/07/2013 1 Name1 Top row is non editable
07/09/2013 2 Name2 Edit Delete
07/11/2013 3 Name3 Edit Delete (date is changed to 07/08/2013).
07/15/2013 4 Name4 Edit Delete
07/20/2013 5 Name5 Edit Delete
The new updated row:
Start date, project_Display_nbr, Name
07/07/2013 1 Name1
07/08/2013 2 Name3 Edit Delete (after date is changed, 3 becomes 2).
07/09/2013 3 Name2 Edit Delete (2 becomes 3)
07/15/2013 4 Name4 Edit Delete
07/20/2013 5 Name5 Edit Delete
I haven't used Virtual & View and how they can be used for the above scenario.
Thanks
|
|
|
|
|
Re: Please help with multiple update [message #602195 is a reply to message #602174] |
Sun, 01 December 2013 04:55 |
|
dariyoosh
Messages: 538 Registered: March 2009 Location: France
|
Senior Member |
|
|
envision2005 wrote on Sun, 01 December 2013 01:03When Editing the row, user is only allowed to change the date in the row. When date is changed then 2 things I need to do: 1) Compare the date of the row changed with the dates of the rest of the rows (up & down). 2) If the date that is updated is less than the above row (for example) then the "project display nbr" is also updated.
As I suggested earlier, I think a view is what you're looking for. Create a view, that includes all columns from your table needed for printing in your data grid preceded by a row_number()
Based on the sample output you posted, there are three columns
- start_date,
- project_display_nbr (which we told you, this should'nt be stored as a column in your table),
- name
What I suggest is something like this
create or replace view your_datagrid_v as
select start_date,
row_number() over (order by start_date asc) project_display_nbr,
name
from yourTable;
After each comitted update or delete, your .Net code has to do a new select on this view to update properly the order of rows in your data grid.
select start_date ,
project_display_nbr ,
name
from your_datagrid_v
order by project_display_nbr asc;
[Updated on: Sun, 01 December 2013 07:35] Report message to a moderator
|
|
|
|
Re: Please help with multiple update [message #602202 is a reply to message #602201] |
Sun, 01 December 2013 08:25 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
envision2005 wrote on Sun, 01 December 2013 19:39Should I drop table view after the process is completed? I mean create a View each time a new process start.
Why? You need not do that. A view is a logical table, it doesn't contain any data. Only it's base tables will have the data which are already present in your DB.
Read the documentation, Create View
Understand how a view works. And then think why do you want to drop it and create every time?
[Updated on: Fri, 07 March 2014 01:43] by Moderator Report message to a moderator
|
|
|
|
|
|
|