Home » SQL & PL/SQL » SQL & PL/SQL » IF is not working right please suggest
IF is not working right please suggest [message #600972] |
Thu, 14 November 2013 05:18 |
|
sahnra
Messages: 39 Registered: November 2013 Location: India
|
Member |
|
|
if
(b.Chek_date between to_date ('Oct-15-2013','mon/dd/yyyy')and to_date ('oct-31-2013','mon/dd/yyyy') then A.pay_frequency IN('2','3','4')
when b.chek_date < to_date('oct-15-2013', 'mon/dd/yyyy') then A.pay_frequency IN('1')
End if
|
|
|
Re: IF is not working right please suggest [message #600973 is a reply to message #600972] |
Thu, 14 November 2013 05:23 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
follow the guidelines. You have now been asked several times in various posts to use code tags, to post test cases and post appropriate explanations of your problem(s). Why do you refuse to follow these requests?
|
|
|
|
|
|
Re: IF is not working right please suggest [message #600985 is a reply to message #600981] |
Thu, 14 November 2013 05:40 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
Post a test case.
Post the full code that you are trying to use.
post an explanation of what you are trying to do.
Put a bit of effort in please, we're not here to do your job for you, we are here to try top help you, but if all you do is post partial bits of code, there is nothing we can do. Your choice.
|
|
|
Re: IF is not working right please suggest [message #600986 is a reply to message #600981] |
Thu, 14 November 2013 05:41 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
sahnra wrote on Thu, 14 November 2013 12:35where check_date is 'Oct-15-2013','mon/dd/yyyy' to 'oct-31-2013' then it will show pay frequency =2,3,5 and
when check_date is less the 'Oct-15-2013' then pay frequency =1
In fact, it is OR as the condition on CHECK_DATE are mutually exclusive.
What about simple AND/ORs?
where ( <check_date is 'Oct-15-2013','mon/dd/yyyy' to 'oct-31-2013'> AND <pay frequency =2,3,5> )
OR ( <check_date is less the 'Oct-15-2013'> AND <pay frequency =1> )
(I will let you to construct conditions between less/greater-then brackets with valid syntax)
|
|
|
Re: IF is not working right please suggest [message #600990 is a reply to message #600986] |
Thu, 14 November 2013 05:50 |
|
sahnra
Messages: 39 Registered: November 2013 Location: India
|
Member |
|
|
SELECT A.COMPANY, A.Process_level, C.Head_company, D.Head_proc_Lev, A.EMPLOYEE,
MAX(B.CHECK_DATE) Last_check_date,Term_date, A.Pay_frequency, A.EMP_STATUS, A.date_hired,
A.adj_hire_date, C.GBU,C.Service_Mgr STM, C.hrp, A.Fica_NBR FROM LAWSON.EMPLOYEE A, LAWSON.PAYMASTR
B, LAWSON.COMPROF C, LAWSON.TAXGROUP D
WHERE
A.EMPLOYEE = B.EMPLOYEE
AND A.PROCESS_LEVEL = C.PROCESS_LEVEL
AND A.COMPANY = B.COMPANY
AND A.COMPANY = C.COMPANY
And A.company = D.company
and A.PROCESS_LEVEL= D.process_level
and (Term_date >to_date ('Oct-02-2013','mon/dd/yyyy') or Term_date = To_date('jan-01-1700','mon/dd/yyyy') )
AND C.COMPANY = '1'
and
if
(b.Chek_date between to_date ('Oct-15-2013','mon/dd/yyyy')and to_date ('oct-31-2013','mon/dd/yyyy') then A.pay_frequency IN('2','3','4')
when b.chek_date < to_date('oct-15-2013', 'mon/dd/yyyy') then A.pay_frequency IN('1')
End if
and A.adj_hire_date < to_date ('Oct-01-2013','mon/dd/yyyy')
Group by A.COMPANY,A.Process_level, C.Head_company, C.National_Name, A.Department, A.EMPLOYEE,
A.Term_date, A.EMP_STATUS, A.date_hired, A.adj_hire_date, B.CHECK_DATE ,C.GBU, C.Service_Mgr, C.hrp,
D.Head_proc_Lev, A.Pay_frequency, A.Fica_NBR
ORDER BY B.CHECK_DATE DESC;
|
|
|
Re: IF is not working right please suggest [message #600991 is a reply to message #600990] |
Thu, 14 November 2013 05:55 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
As has already been said, IF is not valid syntax in SQL. To add to that, you cannot conditionally create a condition i.e. the following is invalid:
where case when x = y then a in (1,2, 3)
else y = m
end;
Take a look at flyboy's suggestion.
You might also consider learning how to format your code in a much more structured manner.
Which do you think is easier to read and debug, yours or this:
select a.company
, a.process_level
, c.head_company
, d.head_proc_lev
, a.employee
, max(b.check_date) last_check_date
, term_date
, a.pay_frequency
, a.emp_status
, a.date_hired
, a.adj_hire_date
, c.gbu
, c.service_mgr stm
, c.hrp
, a.fica_nbr
from lawson.employee a
, lawson.paymastr b
, lawson.comprof c
, lawson.taxgroup d
where a.employee = b.employee
and a.process_level = c.process_level
and a.company = b.company
and a.company = c.company
and a.company = d.company
and a.process_level= d.process_level
and (term_date >to_date ('Oct-02-2013','mon/dd/yyyy')
or term_date = to_date('jan-01-1700','mon/dd/yyyy') )
and c.company = '1'
-- and if (b.chek_date between to_date ('Oct-15-2013','mon/dd/yyyy')and to_date
-- ('oct-31-2013','mon/dd/yyyy') then a.pay_frequency in('2','3','4') when
-- b.chek_date < to_date('oct-15-2013', 'mon/dd/yyyy') then a.pay_frequency
-- in('1')
--end if
and a.adj_hire_date < to_date ('Oct-01-2013','mon/dd/yyyy')
group by a.company
, a.process_level
, c.head_company
, d.head_proc_lev
, a.employee
, term_date
, a.pay_frequency
, a.emp_status
, a.date_hired
, a.adj_hire_date
, c.gbu
, c.service_mgr
, c.hrp
, a.fica_nbr
order by b.check_date desc;
[Updated on: Thu, 14 November 2013 05:58] Report message to a moderator
|
|
|
Re: IF is not working right please suggest [message #600994 is a reply to message #600991] |
Thu, 14 November 2013 06:01 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
@pablolee: that is invalid too as CASE expression supports only expressions in THEN/ELSE clauses (and BOOLEAN conditions are not expressions).
@sahnra:
Ok, if you did not read my previous post, I will take it another way.
IF is PL/SQL statement, so it is described in PL/SQL Language Reference, which is available with other Oracle documentation books e.g. online on http://tahiti.oracle.com/
It is NOT supported in SQL condition. If you want to use some special one, check the chapter about conditions in SQL Language Reference book. It is placed at the same place as the previous one.
Once again: what is wrong with simple AND/OR conditions???
And the last: do NOT invent your own syntax, do follow the one which Oracle supports.
|
|
|
Re: IF is not working right please suggest [message #600998 is a reply to message #600994] |
Thu, 14 November 2013 06:27 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
flyboy wrote on Thu, 14 November 2013 12:01@pablolee: that is invalid too as CASE expression supports only expressions in THEN/ELSE clauses (and BOOLEAN conditions are not expressions). Yes, that's why I said
Quote:the following is invalid: ...
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Wed Apr 24 17:49:27 CDT 2024
|