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 |
Keshaba
Yak Posting Veteran
52 Posts |
Posted - 2008-12-15 : 08:45:42
|
Hi I am using sqlserver 2005 express .I want to know how shall i write a query using if else .Is it possible to do so using sql.I want the query to be like this If marks>75 then result = p else result = f. suppose marks and result are field name in a table.Keshab |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-15 : 09:03:04
|
SELECT *, CASE WHEN Marks > 75 THEN 'p' ELSE 'f' END AS ResultFROM Table1 E 12°55'05.63"N 56°04'39.26" |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-15 : 09:05:34
|
you should be using caseresult = case when marks>75 then p else f end |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-15 : 09:05:51
|
|
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-12-15 : 09:44:25
|
quote: Originally posted by visakh16 you should be using caseresult = case when marks>75 then p else f end
You missed single quotes around p and fMadhivananFailing to plan is Planning to fail |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-15 : 10:35:06
|
quote: Originally posted by madhivanan
quote: Originally posted by visakh16 you should be using caseresult = case when marks>75 then p else f end
You missed single quotes around p and fMadhivananFailing to plan is Planning to fail
what if they are columns and not string values 'p' & 'f' atleast i thought so |
 |
|
|
|
|