Question : SQL UPDATE Script Help needed.

I have a two part question ....

First thing is I need to Identify the procedures where dbo.ProceduresFeeSchedule.ContractTypeCodeMId IS NOT NULL.

from

SELECT
   dbo.ProceduresFeeSchedule.FeeScheduleId,
   dbo.ProceduresFeeSchedule.Fee,
   dbo.ProceduresFeeSchedule.ContractTypeCodeMId,
   dbo.Procedures.Code,
   dbo.Procedures.CPTCode
FROM
   dbo.ProceduresFeeSchedule
INNER JOIN dbo.Procedures ON dbo.ProceduresFeeSchedule.ProceduresId = dbo.Procedures.ProceduresId
WHERE
      RIGHT(p.Code , 1) = 'T' AND
   ( dbo.ProceduresFeeSchedule.FeeScheduleId = 35 ) OR
   ( dbo.ProceduresFeeSchedule.FeeScheduleId = 36 )

I thought I could add in like this, but it returned values in my Code field that did not have a 'T'.

SELECT
   dbo.ProceduresFeeSchedule.FeeScheduleId,
   dbo.ProceduresFeeSchedule.Fee,
   dbo.ProceduresFeeSchedule.ContractTypeCodeMId,
   dbo.Procedures.Code,
   dbo.Procedures.CPTCode
FROM
   dbo.ProceduresFeeSchedule
INNER JOIN dbo.Procedures ON dbo.ProceduresFeeSchedule.ProceduresId = dbo.Procedures.ProceduresId
WHERE
      dbo.ProceduresFeeSchedule.ContractTypeCodeMId IS NOT NULL AND
      RIGHT(p.Code , 1) = 'T' AND
   ( dbo.ProceduresFeeSchedule.FeeScheduleId = 35 ) OR
   ( dbo.ProceduresFeeSchedule.FeeScheduleId = 36 )

After I fix this part, I need to do an update script based off this ....

UPDATE
      ProceduresFeeSchedule
SET
      dbo.ProceduresFeeSchedule.ContractTypeCodeMId = NULL
WHERE  
           ..... my rows where dbo.ProceduresFeeSchedule.ContractTypeCodeMId was not null

Answer : SQL UPDATE Script Help needed.

you were missing logically grouping your OR statement together...which explains why you were getting results you weren't expecting.
Random Solutions  
 
programming4us programming4us