473,549 Members | 3,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 31732
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
2719
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 start at the bottom. What seems to plague many ORM systems is the syntactic confusion and string-manipulation required to build the SQL Statements. If...
4
1976
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 recent entry from not one, but all unique customers, in the most cost effective manner. Table "summary" Attribute | Type | Modifier...
4
5112
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 code using tools-->references. The converted macro included the following statement: DoCmd.OutputTo acQuery, "qselLabelsBloodLog_output",...
2
4233
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 from tbl_BusRequest where iReqTime = '1' and iDeptCode = '1' and cReqType = 'I' group by iDeptCode and
2
1259
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 AM F15947 2 UFG1 7/18/2007 10:32:53 AM F13107 1 UFG1 7/18/2007 10:31:48 AM F15947 2 UFh1 7/18/2007 10:32:53 AM F13107 1 UFh1 </html>
0
1686
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 pointing to a host variable. The ws-custid has value 'C%%%' . the custid field length is 4 . When i use this with cobol db2 it works with display...
8
8682
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 grab the description of that part number and display on the form. I also created a data set for 2 tables both have account# as common field.
3
1716
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 FROM Roles WHERE Roles.RoleName=@inputRoleName)) I am using three tables: Roles, Permissions, and Menu. The error reads like: use of =,<,> etc cannot...
3
1714
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 first select is project and i am asking user to select it by using <?php $sql = "SELECT ProjectName FROM ...
3
9352
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: ID, Name, Desc, ParentID, ParentName, ParentDesc Select statement:
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7809
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1936
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.