Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- using if statement in sql select statement
July 27, 2005, 2:00 pm
rate this thread
How do I use the if then else statement in an SQL statement.
I tried this:
SELECT (IF SSG.ID = SSI.ID then true else false) a, SSG.ID gid, SSG.NAM
gnam, SSI.ID iid, SSI.NAM inam, SSI.NAM inam
FROM SSG, SSI
WHERE SSI.SSG_ID = SSG.ID AND SSI.STA =1 AND ( SSG.ID = SSI.ID OR SSI.SSG_ID
= '10' )
ORDER BY SSG.SOR, SSI.SOR;
What am I doing wrong?
Re: using if statement in sql select statement
From recollection I think it should be something like this:
SELECT IF(SSG.ID = SSI.ID, true, false), a, SSG.ID gid, SSG.NAM gnam,
SSI.ID iid, SSI.NAM inam, SSI.NAM inam
(See also: http://dev.mysql.com/doc/mysql/en/control-flow-functions.html)
It looks like you are using spaces in your field names, I don;t think
this is a very good idea. If you would like to keep names readable the
spaces are most of the times replaced by underscores (_).
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
Q: What is the most annoying thing on usenet and in e-mail?
- » Application confirmation #863062Q Wed, 27 Jul 2005 09:05:17 -0800
- — Previous thread in » MySQL Database Forum
- » Americanas.com SALDO de TVs Com at 80% de Desconto (29798)
- — Newest thread in » MySQL Database Forum