0

I'm getting a SQL exception

Incorrect syntax near ')'

Here is the stored procedure:

if exists(select o.icd10code 
          from ICD10Master.dbo.icd10obginfectiousCrosswalk i
          inner join Icd10TempDisease t on i.icdcode = t.Code1
          where o.trimstatus = @condition   
            and t.[Status] in (0,1))
begin
    select 
        @obgCode = o.icd10code,
        @content = o.trimester,
        @history = t.history 
    from 
        ICD10Master.dbo.icd10obginfectiousCrosswalk i
    inner join 
        Icd10TempDisease t on i.icdcode = t.Code1
    where 
        o.trimstatus = @condition   
        and t.Status in (0,1)

    insert into Icd10TempDisease(disorder, cause, site, site1, site2, manifestation, stage, tconcept1, tconcept2, type, history, finding, code1, annotId, jobid, [content], startId, endId, poa, source, AccountNo, worktype)
    values(999999, 0, 0, 0, 0, 0, 9, 9, 0, 13, @history, 'positive', @obgCode, 0, @jobid, @content, 0, 0, 'N', 'obgcomplications', @accno, @worktype)
end 
else if (@condition = 4)
begin
    select 
        @obgCode = o.icd10code, @content = o.trimester,
        @history = t.history 
    from   
        ICD10Master.dbo.icd10obginfectiousCrosswalk i
    inner join 
        Icd10TempDisease t on i.icdcode = t.Code1 and t.Status in (0, 1, 5)
    inner join 
        ICD10Master.dbo.obgcomplications o on i.obgcode = o.code
    where 
        o.trimstatus = @condition2)

    insert into Icd10TempDisease(disorder, cause, site, site1, site2, manifestation, stage, tconcept1, tconcept2, type, history, finding, code1, annotId, jobid, [content], startId, endId, poa, source, AccountNo, worktype)
    values(999999, 0, 0, 0, 0, 0, 9, 9, 0, 13, @history, 'positive', @obgCode, 0, @jobid, @content, 0, 0, 'N', 'obgcomplications', @accno, @worktype)
end

I'm getting error at if exists condition.

4
  • Additional close bracket in where o.trimstatus =@condition2) which is unnecessary. Removing that will make the query engine happy. Commented Dec 28, 2015 at 5:10
  • I think, it is the bracket in this part of the query[ =@condition2) ] Commented Dec 28, 2015 at 5:10
  • I think alias 'o' is not defined which is used in if exists query. Commented Dec 28, 2015 at 5:15
  • For else if condition of @condition = 4 in where clause you have extra parenthesis. Commented Dec 28, 2015 at 6:37

1 Answer 1

1

You have an extra (unnecessary) closing parenthesis at the end of your second SELECT statement. Remove it and the error should go away:

select @obgCode = o.icd10code,@content = o.trimester,@history = t.history from   ICD10Master.dbo.icd10obginfectiousCrosswalk i
inner join Icd10TempDisease t on i.icdcode = t.Code1 and t.Status in(0,1,5)
inner join ICD10Master.dbo.obgcomplications o on i.obgcode=o.code
where o.trimstatus =@condition2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.