select with elsif

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
  

Poston Mon, 16 Oct 2006 5:39 pm

Hello to all I need to do a select that seeks a proceddimento performed on a patient for example: If procedure = 111046 then if 1 = procedure 111047 then if 2 = procedure 111048 then 4 If procedure = 111049 then 4 if not looking for date of last attendance in q the procedure has been the 1110 48 or 111049 and if the date is < = 5 years then 4 Note: the proceimentos above are for vaccines and indicate if the patient took the first dose (1) or the second dose (2) and took the third or reinforcement (4) who bothers to be immune. But in case you haven't taken, within a period, then checks if the last 5 years he took the 3rd dose or strengthening; condition that is also considered immune to disease.


from already thank you for your help. All my doubts I have found here on the website. já divulgeui to several people for a bunch of inclisive oracle q certificaçaão this happening in sp (senac) and were very satisifeito with the site, including my boss, q this doing this course. So congratulations!!!
Joao Moraes
Location: Botucatu - SP

Poston Mon, 16 Oct 2006 5:43 pm

dr_gori
Location: Portland, OR USA

Thomas F. G

Você já respondeu a dúvida de alguém hoje?
http://glufke.net/oracle/search.php?search_id=unanswered

Poston Thu, 18 Jan 2007 1:44 pm

Hello, John Mathew See the script below:
Code: Select all
DECLARE
li_procedimento number := 111048;
ld_data             date := to_date('18/01/2000', 'DD/MM/YYYY');
v_resultado       varchar2(30);
BEGIN
select case when li_procedimento = 111046 then
           '1ª Dose'
       else
           case when li_procedimento = 111047 then
               '2ª Dose'   
           else
               case when li_procedimento = 111048 then
                   '3ª Dose'
               else
                   case when li_procedimento = 111049 then
                       '4ª Dose'
                   else
                       case when months_between(sysdate, ld_data) <= 60 then
                           '4ª Dose'
                       else
                            'Última data tem mais de 5 anos'
                       end
                   end
               end
           end
       end
  into v_resultado
  from dual;
 
dbms_output.put_line('Resultado: ' || v_resultado);
END;
PS1: the li_procedimento would be a column of the table.

PS2: In your case, instead of ld_data, could be used a function to get the date of last attendance in that the procedure has been the 111048 or 111049. , PS3: it is a pity, but when we send the msg, we lost the indentation.


I hope I helped!

Regards, Álvaro
asarmento
Location: Salvador - BA


  • See also
    Replies
    Views
    Last Post


Return to SQL

Who is online

Users browsing this forum: No registered users and 2 guests