Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF-else inSQL

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi,
i am a novice SQL user. i have a problem for which i need to use if else statement. Can i use it in SQL.
the example:

if main_class="M"
select a, b, c
from z
where mt_policy=z.aci_doc_no1(i have to use this if doc_type=p)
where cc_policy=z.aci_doc_no1(i have to use this if doc_type=b)

if main_class<>&quot;M&quot;
select s, a, m
from z
where mt_policy=z.aci_doc_no1(i have to use this if doc_type=p)
where cc_policy=z.aci_doc_no1(i have to use this if doc_type=b)


 
Use a combination of AND and OR in the where clause.

Example:
if main_class=&quot;M&quot;
Select a, b, c
From z
Where (doc_type='p' And mt_policy=z.aci_doc_no1)
Or (doc_type='b' And cc_policy=z.aci_doc_no1)
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top