Jump to content

Snow Brothers Sunny Leone Ni Esara..


spidereddy

Recommended Posts

sry for misleading title..
 
 
 
select 
    decode(sal_1,0,null,
    (sum(case when date_key between to_char(add_months(sysdate,-12),'YYYYMM') and to_char(sysdate,'YYYYMM') then salary/sal_1  end))) as annual_sal 
    from employee
    group by emp_key,sal_1;
 
or
 
    select 
    case when sal_1<>0 then
    sum(case when date_key between to_char(add_months(sysdate,-12),'YYYYMM') and to_char(sysdate,'YYYYMM') then salary/sal_1  end)end as annual_sal 
    from employee
    group by emp_key,sal_1;
 
paina queries execute chesthe 'divisor is equal to zero' error osthundhi..
 
 
if i add a filter condition to consider only positive values..then its working..
 
  select 
    case when sal_1<>0 then
    sum(case when date_key between to_char(add_months(sysdate,-12),'YYYYMM') and to_char(sysdate,'YYYYMM') then salary/sal_1  end)end as annual_sal 
    from employee
    group by emp_key,sal_1;
 
 
but i want to get the same result for negative values too..

 

Link to comment
Share on other sites

  • Replies 48
  • Created
  • Last Reply

Top Posters In This Topic

  • babugaru

    16

  • spidereddy

    15

  • pandugadu999

    2

  • Posaani

    2

Top Posters In This Topic

 

sry for misleading title..
 
 
 
select 
    decode(sal_1,0,null,
    (sum(case when date_key between to_char(add_months(sysdate,-12),'YYYYMM') and to_char(sysdate,'YYYYMM') then salary/sal_1  end))) as annual_sal 
    from employee
    group by emp_key,sal_1;
 
or
 
    select 
    case when sal_1<>0 then
    sum(case when date_key between to_char(add_months(sysdate,-12),'YYYYMM') and to_char(sysdate,'YYYYMM') then salary/sal_1  end)end as annual_sal 
    from employee
    group by emp_key,sal_1;
 
paina queries execute chesthe 'divisor is equal to zero' error osthundhi..
 
 
if i add a filter condition to consider only positive values..then its working..
 
  select 
    case when sal_1<>0 then
    sum(case when date_key between to_char(add_months(sysdate,-12),'YYYYMM') and to_char(sysdate,'YYYYMM') then salary/sal_1  end)end as annual_sal 
    from employee
    group by emp_key,sal_1;
 
 
but i want to get the same result for negative values too..

 

 

SELECT   DECODE (
                 sal_1,
                 0,
                 NULL,
                 (SUM(CASE
                         WHEN date_key BETWEEN TO_CHAR (
                                                  ADD_MONTHS (SYSDATE, -12),
                                                  'YYYYMM'
                                               )
                                           AND  TO_CHAR (SYSDATE, 'YYYYMM')
                         THEN
                            salary / sal_1
                      END))
              )
                 AS annual_sal
       FROM   employee
   GROUP BY   emp_key, sal_1;
 
 
NULL value osthundi emo adi kuda handle cheyyi
Link to comment
Share on other sites

 

SELECT   DECODE (
                 sal_1,
                 0,
                 NULL,
                 (SUM(CASE
                         WHEN date_key BETWEEN TO_CHAR (
                                                  ADD_MONTHS (SYSDATE, -12),
                                                  'YYYYMM'
                                               )
                                           AND  TO_CHAR (SYSDATE, 'YYYYMM')
                         THEN
                            salary / sal_1
                      END))
              )
                 AS annual_sal
       FROM   employee
   GROUP BY   emp_key, sal_1;
 
 
NULL value osthundi emo adi kuda handle cheyyi

 

 

nu em changes cheshnavo nak ardam katle bhayya..koncham xplain pls..

Link to comment
Share on other sites

I mean sal_1 value NULL ocche chances undaoccha ? 

 

yep sal_1 null oche chance undhi..andhke case statement petta kada 'case when sal_1 <> 0' ani..

Link to comment
Share on other sites

nu em changes cheshnavo nak ardam katle bhayya..koncham xplain pls..

lol .. nenu em change cheyyale .. nuvvu icchina first query baga confusing ga undi anduke first danni format chesa..

 

So nuvvu sal_1 value '0' aithe condition ni handle chesthunnav kaani sal_1 value NULL aithe still fail aithadi kada. SO decode lo aan condition add chesi try cheyyamantunna

Link to comment
Share on other sites

lol .. nenu em change cheyyale .. nuvvu icchina first query baga confusing ga undi anduke first danni format chesa..

 

So nuvvu sal_1 value '0' aithe condition ni handle chesthunnav kaani sal_1 value NULL aithe still fail aithadi kada. SO decode lo aan condition add chesi try cheyyamantunna

 

2nd query chudu..

Link to comment
Share on other sites

×
×
  • Create New...