sql server - How can I use IF statement in sql stored-procedure -


i want transform sql query procedure in sql server, have issue in if statement.

this logic want implement:

//if patientstatus equals "all" there no condition  patientstatus.tostring() == "all" ? "" : (       patientstatus.tostring() == "out"        ? " , cms_encounter.encounter_end_time not null"        :" , cms_encounter.encounter_end_time null " ) 

after searching how use if statement in stored procedures, came out this, it has errors:

if(@patient_status != 'all')  begin    if(@patient_status = 'out')      begin        , cms_encounter.encounter_end_time not null      end     else       begin        , cms_encounter.encounter_end_time null       end          end 

you can combine and , or conditions result desire. can use below query:

select * tablename cms_encounter      (@patient_status = 'all') or     (@patient_status = 'out' , cms_encounter.encounter_end_time not null) or      (@patient_status <> 'out' , cms_encounter.encounter_end_time null) 

in case first evaluate condition @patient_status = 'all'. if evaluates true, results. if evaluates false, other conditions evaluated.

second condition ((@patient_status = 'out' , cms_encounter.encounter_end_time not null) evaluated when patient status out, otherwise third condition evaluated.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -