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 |
|
boehnc
Starting Member
15 Posts |
Posted - 2012-02-16 : 15:20:02
|
| I have a query..already with select *,from table1now I need to look at two columns, if they meet certain criteria, I need to pruduce a certain value in another column. For example:Column1, Column2, Column3 (calculated column)CABG, 145, 1KPRO, 138, 0So, if column1 = CABG, and Column2 > 120 (has to be a CABG), then Column3 = 1, if not (CABG greater than 120), then 0.I will then have to do the same thing with KPRO with a value of > 100 in column2. any help is appreciated. |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-02-16 : 15:24:32
|
As you correctly guessed, you can use a case expression in your select statement, for example:SELECTCASE WHEN (column1 = 'CABG' AND Column2 > 120) OR (column1 = 'KPRO' AND Column2 > 120) THEN 1 ELSE 0 END AS Column3FROM YOURTable; |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
boehnc
Starting Member
15 Posts |
Posted - 2012-02-16 : 16:02:08
|
| awesome..thanks! |
 |
|
|
|
|
|
|
|