If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > need help implementing IF..ELSE

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-13-03, 01:15
aurel1412 aurel1412 is offline
Registered User
 
Join Date: Dec 2003
Posts: 14
need help implementing IF..ELSE

Hi,

im really now with sql so can anyone give an example on this problem?
i dont know how to implement this kind of logic in sql:

if (ID != null)
print name
else print "not available"

i was thinking about using case, but i'm not sure how to implement printing a string in a case statement using sql
sorry for the language term...i'm really used to java, so i always think in java term when im doing programming

thanks
Reply With Quote
  #2 (permalink)  
Old 12-13-03, 02:19
aus aus is offline
Registered User
 
Join Date: Oct 2003
Location: Denver, Colorado
Posts: 137
In MySQL, you want to use a statement like:

SELECT IF(ISNULL(ID), 'Not Available', Name), ...
Reply With Quote
  #3 (permalink)  
Old 12-16-03, 06:37
aurel1412 aurel1412 is offline
Registered User
 
Join Date: Dec 2003
Posts: 14
this is how i do it....

SELECT IF(ISNULL("Student"."ID"),
'Not Available',
"Student"."LastName"),
COMPUTER.SerialNumber "Serial Number"
FROM COMPUTER left join Student
ON "Student"."ID" = COMPUTER.ID
ORDER BY COMPUTER.SerialNumber
;


but it gives me this error:

SELECT IF(ISNULL("PERSON"."PersonID"), 'Not Available', "PERSON"."LastName"),
*
ERROR at line 1:
ORA-00904: "IF": invalid identifier


What's wrong??????
someone PLSSSS HELP
Reply With Quote
  #4 (permalink)  
Old 12-16-03, 06:51
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,533
why are you getting an oracle error message from mysql?

this is the mysql forum


try this, it is standard sql and works in all databases that support standard sql --
Code:
select case when  is null
            then 'not available'
            else student.lastname
         end
     , computer.serialnumber as "serial number"
  from computer 
left outer
  join student
    on computer.id = student.id
order 
    by computer.serialnumber
rudy
http://r937.com/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On