I have the SQL below and want to update the managerNTID with @managerNTID only if the users DB record has StopManagerOverride value of 0, if it is set to 1 on the record then I don’t want to update this field:
UPDATE ee
SET
MangerId = CASE ee.ShopManagerOverride
WHEN 0 THEN @MangerId
ELSE ee.MangerId
END
,ManagerNTID = CASE ee.ShopManagerOverride
WHEN 0 THEN @managerNTID
ELSE ee.ManagerNTID
END
,NTID = @NTID
,FirstName = @FirstName
,LastName = @LastName
,FullName = @FullName
,ReportingGroup = @ReportingGroup
,DistinguishedName = @DistinguishedName
,IsActive = 1
--,StopManagerOverride= 1
,LastUpdate = GETDATE()
,UpdateBy = @UpdateBy
FROM dbo.Employees ee
Inner Join dbo.Employees e ON e.NTID = ee.NTID
WHERE ee.NTID = @NTID
Thoughts on how to make this one field in the update have an inline condition?
edit: i am almost there, just need to resolve some ambiguous columns now. my eyes are red from this already.
You could try something like this – if the
ShopManagerOverrideis set to 1, update it to the parameter value passed in, otherwise update it to the value it already has (I’m also assuming your field is reallyManagerId– notMangerId– right??):Untested, straight and “free hand” from my brain – hope I got the syntax right! Try it – does it work, does it do what you’re looking for??