Job number needs to be updated if prework 1 and prework 1 line displayed instead prework 0, if prework 1 exists. Most of the records have only prework 0.
mine is a different way of doing this !!!
if it helps ... great ...
i love any feedback ...thanks
drop create data ...
drop table #temp
go
create table #temp
(
Job varchar(100),
Prework int,
jobDate date,
key1 int
)
go
insert into #temp select '' ,1,'2019-05-30',3891
insert into #temp select 'BBC00321',0,'2019-05-31',3891
insert into #temp select '' ,1,'2019-09-11',3245
insert into #temp select 'BBC00309',0,'2019-10-31',3245
insert into #temp select 'BBC00391',0,'2019-05-31',3892
insert into #temp select 'BBC00396',0,'2019-06-09',3801
go
select * from #temp
go
SQL .. different ..way
SELECT a.job,
Iif(b.prework = 1, 1, 0),
Iif(b.prework = 1, b.jobdate, a.jobdate),
Iif(b.key1 IS NULL, a.key1, a.key1)
FROM (SELECT *
FROM #temp
WHERE prework = 0) a
LEFT JOIN (SELECT *
FROM #temp
WHERE prework = 1) b
ON a.key1 = b.key1