Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
dacow
Starting Member
5 Posts |
Posted - 2010-12-10 : 08:00:38
|
hi.Im trying to compare 2 fields in the select like this. (this code doesnt work)select *, isSomething = ( fiel1 > field2 )from mytableThe next code works fineselect *, myCalc = ( fiel1 + field2 )from mytablehow can i compare the fields like the first code, to get a new column that gives me some extra information.I expect isSomething be a column with values true/false or a 1/0 or something similar.pd: sorry bout my bad english  |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2010-12-10 : 08:12:05
|
| What you need is a simple CASE statement:select *, isSomething = CASE WHEN field1 > field2 THEN 'GreaterThan' ELSE 'SmallerThanOrEqual' ENDfrom mytable- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-12-10 : 08:17:36
|
| You can use Case statement. Something like : select Name, Case when schema_ver > category Then 'True' else 'False' end from sysobjectsRegards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-12-10 : 08:18:37
|
quote: Originally posted by Lumbago What you need is a simple CASE statement:select *, isSomething = CASE WHEN field1 > field2 THEN 'GreaterThan' ELSE 'SmallerThanOrEqual' ENDfrom mytable- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com
I am 5 minutes late |
 |
|
|
dacow
Starting Member
5 Posts |
Posted - 2010-12-10 : 08:44:50
|
thank you both, and both were super fast to asnwer CASE is new to me so im goin to read bout it. Thanks again. |
 |
|
|
|
|
|