SQL Update statement help

Rage187

Lifer
Dec 30, 2000
14,276
4
81
I do support for a POS system and the users have found some way to screw things up.

I have two table that are giving me issues

1. Shifts - with columns SfActionDate, SfTillClose, Sfcode

2. Receiptbase - with columns rcbShiftDate, rcbActionDate, rcbShiftnum


When someone logs in for the day, it puts a 0 in the SftillClose, when they logout for the day it puts a 1.

Somehow the users have been able to have the 0 on one date and the closing on another. If this happens the program will not allow them to "close the drawer" for the day.

I had been identifying which Sfcode has the issue by doing the following:

Select * from shifts where sftillclose=0 and sfactiondate= '2007-??-??'
-ed where the ?? equals the date I can not close the drawer on

I then find the offending SFcode which joins Receiptbase on rcbShiftnum

select * from receiptbase where rcbshiftnum=???

I had manually been fixing these everyday it happened using the following script updated with that date and the offending shiftnum(s)

update shifts set sfactiondate= '2007-03-26' where sfcode in (7172,7241)
update recieptbase set rcbshiftdate = '2007-3-26' where rcbshiftnum in
(7172,7241)

when the update is ran, all the closing and opening happen on the same date and all the sales have the same date. I can then finally close the drawer.

But I have been doing this for 2 months while waiting on the devs to fix it. And it's mind numbing,

What I need is a update statement that will automate the process without having to give it dates or shift numbers.

 

lozina

Lifer
Sep 10, 2001
11,711
8
81
Sounds to me like the application is always doing an insert into Shifts, so it's inserting one row when the person logs in with a 0, then they logout it creates an entirely new row with the 1 and the same date.

So when you run that statement to select all shifts where there is a 0, you will of course get results since that row with the 0 is still there in addition to the one with a 1.

Is that right?

If so maybe a quick workaround could be:

Select * from shifts where shifts.sftillclose=0 and shifts.sfactiondate= '2007-??-??' and not exists (select 1 from shifts where sftillclose=1 and sfactiondate= '2007-??-??' and sfcode = shifts.sfcode)

assuming sfcode is the primary key for that table..

but the real fix would be that instead of always inserting, when they logout it needs to update the previous row by setting it to 1 so then there is no duplicate rows for the same day but different data.

Apologies if I misunderstood something!
 

Rage187

Lifer
Dec 30, 2000
14,276
4
81
I just need to be able to update both tables and make sure that the sfactiondate, rcbshiftdate, rcbactiondate all are using the same date as the row in Shifts where SfTillclose=0 and not exists in shifts where sftillclose=1

I just don't want to have to update the statement with a date or shiftnum. I could even set it up as a job to run at the end of the day to resolve the issue until the devs get a chance to look at it.
 

KLin

Lifer
Feb 29, 2000
30,207
558
126
I don't understand why you are using sfactiondate in the where clause to find the record where sftillclose is = 0. Is the date wrong also in the shifts table?


EDIT: Can you give a small data example? a couple records from shifts and a few related records from receiptbase?
 

Rage187

Lifer
Dec 30, 2000
14,276
4
81
Originally posted by: KLin
I don't understand why you are using sfactiondate in the where clause to find the record where sftillclose is = 0. Is the date wrong also in the shifts table?


EDIT: Can you give a small data example? a couple records from shifts and a few related records from receiptbase?

YHPM

 

KLin

Lifer
Feb 29, 2000
30,207
558
126
Originally posted by: Rage187
Originally posted by: KLin
I don't understand why you are using sfactiondate in the where clause to find the record where sftillclose is = 0. Is the date wrong also in the shifts table?


EDIT: Can you give a small data example? a couple records from shifts and a few related records from receiptbase?

YHPM

Right back at ya.
 

ncage

Golden Member
Jan 14, 2001
1,608
0
71
Originally posted by: Rage187
I do support for a POS system and the users have found some way to screw things up.

I have two table that are giving me issues

1. Shifts - with columns SfActionDate, SfTillClose, Sfcode

2. Receiptbase - with columns rcbShiftDate, rcbActionDate, rcbShiftnum


When someone logs in for the day, it puts a 0 in the SftillClose, when they logout for the day it puts a 1.

Somehow the users have been able to have the 0 on one date and the closing on another. If this happens the program will not allow them to "close the drawer" for the day.

I had been identifying which Sfcode has the issue by doing the following:

Select * from shifts where sftillclose=0 and sfactiondate= '2007-??-??'
-ed where the ?? equals the date I can not close the drawer on

I then find the offending SFcode which joins Receiptbase on rcbShiftnum

select * from receiptbase where rcbshiftnum=???

I had manually been fixing these everyday it happened using the following script updated with that date and the offending shiftnum(s)

update shifts set sfactiondate= '2007-03-26' where sfcode in (7172,7241)
update recieptbase set rcbshiftdate = '2007-3-26' where rcbshiftnum in
(7172,7241)

when the update is ran, all the closing and opening happen on the same date and all the sales have the same date. I can then finally close the drawer.

But I have been doing this for 2 months while waiting on the devs to fix it. And it's mind numbing,

What I need is a update statement that will automate the process without having to give it dates or shift numbers.


Rage i write SQL every day so i'm pretty good at it. With you description i'm kind cloudy on your business rules and if thats the only columns in those two tables above then the developer/dba needs to be shot especially if those two tables are supposed to be related. Where is the Primary Key? There are just to many inderminates in the information you give:
1) I assuming that multiple people log in for the day so how do you tell one person from another? SFCode (whatever that stands for)?
2) I assume when someone logs in/out then two records will be created for them. One with a SFTillClose = 0 and one with a SFTTillClose = 1.


I you can provide me details of exactly what happens with these tables and when they get either get updated/inserted then im sure i can help you.

Ncage
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |