Link to home
Start Free TrialLog in
Avatar of Stacie
StacieFlag for United States of America

asked on

Updating a field based from a if exist....

Lets say I have this query below and it return some value I would like to change the value of t.fieldC = 10 instead of t.field = 0

if exist( not sure what to do here

select t.fieldA  from yourtable t
 where t.fieldB = 'export'
  and t.fieldC = 0
 and exists( select null  from yourtable o
   where o.fieldA = t.fieldA
    and o.fieldB = 'export b'
     and o.fieldC = 10
)
Avatar of jitendra patil
jitendra patil
Flag of India image

IF EXISTS(select t.fieldA  from yourtable t  where t.fieldB = 'export' and t.fieldC = 0)
BEGIN
       -- your update statement goes here
END
ELSE
 BEGIN
 --- your else condition or whatever you want to return.
END

hope this helps.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial