473,396 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

using if statement in sql select statement

Hi Folk

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?

- Nicolaas
Jul 26 '05 #1
1 31722
windandwaves wrote:
Hi Folk

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?

- Nicolaas


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/co...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 (_).

Good luck!

Jonathan

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 27 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to...
4
by: Dave [Hawk-Systems] | last post by:
have a data table that records entries by date(unix timestamp) and customer number. each custnum will have several entries showing a running ledger type snapshot. we have the need to get the most...
4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
2
by: intscript | last post by:
Hello everyone! Is this statement is possible? here is the code: select sum(nPassengers) Planned, Actual, (sum(Planned) - Actual) Variance from ( select iDeptCode, sum(nPassengers) Planned...
2
basti42
by: basti42 | last post by:
<html> time article status ufmc 7/18/2007 10:30:08 AM F15947 1 UFG1 7/18/2007 10:30:43 AM F15947 2 UFG1 7/18/2007 10:31:13 AM F15947 2 UFG1 7/18/2007 10:31:48...
0
by: ramcouser | last post by:
Hi I am trying to select multiple rows from my table based on the search criteria. in cics cobol. with a host variable. i am using a SELECT statement with LIKE :ws-custid. here the like is...
8
by: Mehbs | last post by:
I created a very simple form. There are 2 text boxes; 1 for entering account number and other to display its desription. I also placed buttom so when it is clicked, select statement underneath...
3
by: sangam56 | last post by:
Hello!I am using following sql statement: SELECT Menu.MenuID,Menu.TextUrl FROM Menu WHERE Menu.MenuID= (SELECT Permissions.MenuID FROM Permissions WHERE Permissions.RoleID=(SELECT Roles.RoleID...
3
by: micky125 | last post by:
Hey guys I have been checking the forum for a way to populate a second select field depending on the choice made from the first one. Basically i am working on projects and the delays that occur. The...
3
by: bkoh | last post by:
Hi all, I am populating data from a table which contain parent id which reference to itself E.g.: TableA - ID, Name, Desc, ParentID ParentID reference to ID I would need the result to return:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.