Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 not sure how to fix logic change

Author  Topic 

-jay-
Starting Member

14 Posts

Posted - 2011-03-30 : 10:50:57
would appreciate it if someone could help.

Got a request to change logic in this, but not sure how.



--CPS CALCUALTIONS
--Scheduled Date = Earliest of MFG_NEED and CURR_LATE_FINISH
print 'PROCESS TOLLGATE TG500-1 CALCULATIONS'
go
update
tg500_1
set
required_date = convert(char, tmp1.scheduled_date, 101)
from
tg500_1,
(select distinct
record_num,
min(scheduled_date) as scheduled_date
from
(select record_num, mfg_need as scheduled_date from tg500_1 where mfg_need is not null
union
select record_num, curr_late_finish as scheduled_date from tg500_1 where curr_late_finish is not null) tmp
group by
record_num) tmp1
where
tg500_1.record_num = tmp1.record_num


here is logic change.

Current logic
Schedule date = Earliest of MFG_NEED and CURR_LATE_FINISH

Revised Logic
Schedule date = MFG_NEED if MFG_NEED empty CURR_LATE_FINISH

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-03-30 : 11:45:46
I think this would do it, but sometimes my thoughts have been very wrong in the past, so please test to see it does what you are looking for.
quote:
Originally posted by -jay-

would appreciate it if someone could help.

Got a request to change logic in this, but not sure how.



--CPS CALCUALTIONS
--Scheduled Date = Earliest of MFG_NEED and CURR_LATE_FINISH
print 'PROCESS TOLLGATE TG500-1 CALCULATIONS'
go
update
tg500_1
set
required_date = convert(char, tmp1.scheduled_date, 101)
from
tg500_1,
(select distinct
record_num,
min(scheduled_date) as scheduled_date
from
(select record_num, mfg_need as scheduled_date from tg500_1 where mfg_need is not null
union
select record_num, curr_late_finish as scheduled_date from tg500_1 where curr_late_finish is not null

select
record_num,
case when mfg_need is null then curr_late_finish else mfg_need end as scheduled_date
from
tg500_1

) tmp
group by
record_num) tmp1
where
tg500_1.record_num = tmp1.record_num


here is logic change.

Current logic
Schedule date = Earliest of MFG_NEED and CURR_LATE_FINISH

Revised Logic
Schedule date = MFG_NEED if MFG_NEED empty CURR_LATE_FINISH


Go to Top of Page
   

- Advertisement -