SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 if statement inside sql query??
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

asksql
Starting Member

11 Posts

Posted - 06/07/2008 :  03:00:28  Show Profile  Reply with Quote
Hello,

I have an if statement for one of my columns in my query.
I want to write the if statement as a part of my select statement.
How would I do that. Do to a couple of rules I am not allowed to write a stored procedure for this.

I could use the "decode function" but

I have something like this:
if column1 = '1' or column2 = '2' then select "Yes" etc..

I tried doing select decode (column1 or column2, , , ) but it doesn't work.
Any ideas?

SwePeso
Patron Saint of Lost Yaks

Sweden
30282 Posts

Posted - 06/07/2008 :  03:22:17  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT *,
CASE WHEN Column1 = '1' OR Column2 = '2' THEN 'Yes'
WHEN Column1 = '2' THEN 'Maybe'
WHEN Column2 = '1' THEN 'Never'
ELSE 'I don't know'
END
FROM Table1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000