473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Comparing and updating values in same table but in different rows

Hi all,

My company database has been screwed and I need to build a query to fix. It has to be done by query.

There are many rows for services of same customer that their start date and end date are clashing. Customers can have one current service at a time. The system does not allow multiple current values during processing, and it throws lots of errors.

Current data:

Table name: Services
CUSTNUM START_DATE END_DATE SERVICE
------- ---------- --------- ---------
A 18-JUL-08 27-SEP-09 RCBR1
A 28-SEP-09 09-MAR-10 RCBR2
A 10-MAR-10 30-JUN-10 RCBR3
A 01-JUL-10 (Null) RCBR4
B 05-JAN-09 09-JAN-09 RCBR1
B 10-JAN-09 (Null) RCBR2
B 01-JUL-10 (Null) RCBR3
...
...

Problem: Customer A has both service 3 and 4 from 01-JUL-10 to 06-JUL-10. They are invalid in my system as it validates a single current service. Customer B has two services (2 and 3) from 10-JAN-09. These should be changed to:

CUSTNUM START_DATE END_DATE SERVICE
------- ---------- --------- ---------
A 18-JUL-08 27-SEP-09 RCBR1
A 28-SEP-09 09-MAR-10 RCBR2
A 10-MAR-10 30-JUN-10 RCBR3
A 01-JUL-10 (Null) RCBR4
B 05-JAN-09 09-JAN-09 RCBR1
B 10-JAN-09 30-JUN-10 RCBR2
B 01-JUL-10 (Null) RCBR3

Could you please explain me how I achieve this by using SQL only?

Thanks in advance.
Aug 24 '10 #1
1 1884
yarbrough40
320 100+
am I missing something? do you just want to update the END_DATE value for that record?

Expand|Select|Wrap|Line Numbers
  1. UPDATE MyTableName SET END_DATE = '30-JUN-10' WHERE CUSTNUM = 'B' AND START_DATE = '10-JAN-09' AND SERVICE = 'RCBR2'
  2.  
  3.  
Aug 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

35
by: Dirk Bruere at Neopax | last post by:
Is it possible to have one table somehow 'called' to appear on different pages? I want something to appear on all pages, yet only want to (re)edit one item. -- Dirk The Consensus:- The...
2
by: cyder | last post by:
Hi All I want to create a filter that will detect whether I have the same value in say field 3 and field 4. Could you please tell me how to do this? Thanks Cydernet
1
by: Anu139 | last post by:
the table is col1 --------- M S S Q L The expected Result is
3
by: nihal123 | last post by:
COSIDER THE DATA Year Grade TOT SAL --------- -------------- ---------- - SAM G dIAS ------------------------------------- 2003 X1 2964.00 3041.08...
2
by: idioteque | last post by:
If I have the following table: Client# ....... Value 24 ................ A 24 ................ G 24 ................ F 25 ................ A 25 ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.