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 |
|
pithhelmet
Posting Yak Master
183 Posts |
Posted - 2005-08-16 : 10:08:17
|
| Hi everyone,I have a boolean field in the table, and during the course of a select, i would liketo return a text constant instead of the boolean value.for example, if the value is a 0, theni would like the string returned to be 'Pending'and if the value is a 1, then the valuereturned needs to be 'Sumitted'Please advise if i can accomplish this in the query,and howthankstony |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-16 : 10:10:22
|
| [code]Select othercolumns, case when booleanField=0 then 'Pending' else 'Submitted' endfrom yourtable[/code]MadhivananFailing to plan is Planning to fail |
 |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2005-08-16 : 10:11:45
|
| You should probably have a table with the correct values in and join to it, but if you insist on doing the work within the code, then you can use a CASE statement.SELECT CASE when yourvalue = 0 then 'Pending' else 'Submitted' end as yourvalue FROM blah-------Moo. :) |
 |
|
|
pithhelmet
Posting Yak Master
183 Posts |
Posted - 2005-08-16 : 10:28:19
|
| Here is the query that is provided....SELECT mresi_lkey, mresi_boolSubmitted, mresi_dtsampledatetime, mresi_szsampleid, dspt_szname, dev_szcode, (mresi_szoperatorlname + ', ' + mresi_szoperatorfname + ' ' + ISNULL(mresi_szoperatormi, '')) as namefield, (mresi_szoperatorfacility + ' / ' + mresi_szoperatorlocation) as facloc FROM tblMRESampleInformation INNER JOIN tblDisposableType ON tblMRESampleInformation.MRESI_lfkDT = tblDisposableType.DSPT_lKey INNER JOIN tblDevice ON tblDisposableType.DSPT_lfkDEVKey = tblDevice.DEV_lKEY LEFT OUTER JOIN tblMREResultInformation ON tblMRESampleInformation.MRESI_lKey = tblMREResultInformation.MRERI_lKey where mresi_boolsubmitted <> 99 ORDER BY MRESI_lKeyI was thinking somewhere in the (mresi_szoperatorfacility + ' / ' + mresi_szoperatorlocation) as facloc line of code to add in the select???thanks for the help!!take caretony |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-16 : 10:30:32
|
| Yes you can add it at the last column of the queryMadhivananFailing to plan is Planning to fail |
 |
|
|
pithhelmet
Posting Yak Master
183 Posts |
Posted - 2005-08-16 : 10:34:45
|
| PERFECT!!thanks a million for ya'lls help! |
 |
|
|
|
|
|
|
|