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 |
|
cwildeman
Starting Member
40 Posts |
Posted - 2010-12-30 : 10:20:00
|
| Hi,I receive a report from a proprietary system that has a field called [Wound #1] that has text values of Yes or No. I would then import this to an Access table and create a query with a field called Wound and assigned a value of 1 if [Wound #1] is Yes and 0 if no. I want to move this to SQL Server and am having trouble converting the IIF statement to Case When Else. Here is my access query. Can someone help? Thanks, Chuck SELECT HAPU.[Patient Name], HAPU.[Patient MRN], HAPU.[Account Number], HAPU.[Act Discharge Date], HAPU.[Admit Date], HAPU.[Attend Physician], HAPU.[Encounter Facility], IIf([Wound #1]="Yes",1,0) AS Wound, 1 AS PTCount, HAPU.[Unit HAPU Occured] AS Unit, HAPU.[Wound Stage] AS Stage, HAPU.Consult, HAPU.CreatedInError, tblDays.TrxMonth AS [Month]FROM HAPU INNER JOIN tblDays ON HAPU.Consult = tblDays.TrxDayWHERE (((IIf([Wound #1]="Yes",1,0))>0) AND ((HAPU.CreatedInError) Is Null))Chuck W |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-12-30 : 10:39:50
|
ChangeIIf([Wound #1]="Yes",1,0) AS Wound, toCASE [Wound #1] WHEN 'Yes' THEN 1 WHEN 'No' THEN 0 ELSE 0 END) AS Wound, (you can use a different value for the ELSE if you like - e.g. NULL)andWHERE (((IIf([Wound #1]="Yes",1,0))>0) toWHERE [Wound #1] = 'Yes' |
 |
|
|
cwildeman
Starting Member
40 Posts |
Posted - 2010-12-30 : 11:24:47
|
| Thanks. That worked. ChuckChuck W |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-12-31 : 04:46:49
|
| CASE [Wound #1] WHEN 'Yes' THEN 1 WHEN 'No' THEN 0 ELSE 0 END) AS Wound,is equal toCASE [Wound #1] WHEN 'Yes' THEN 1 ELSE 0 END) AS Wound,MadhivananFailing to plan is Planning to fail |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2011-01-01 : 19:57:10
|
| "CASE [Wound #1] WHEN 'Yes' THEN 1 WHEN 'No' THEN 0 ELSE 0 END) AS Wound,is equal toCASE [Wound #1] WHEN 'Yes' THEN 1 ELSE 0 END) AS Wound,"Indeed, I only offered it on the basis that the O/P might want to handle the case where [Wound #1] was NOT either "Yes" or "No" and return an explicit/different value to indicate the error(The close parenthesis should not have been present in my original ... ) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-01-03 : 04:18:34
|
Ok. I was thinking that IIf([Wound #1]="Yes",1,0) means what I specified. It wont handle more than two conditions MadhivananFailing to plan is Planning to fail |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2011-01-03 : 04:35:15
|
Yes, you are quite right - its just my coding style Madhi We don't codeIF @XXX = 'Yes' THEN 1 ELSE 0 ENDever!!! because we want the application to "break" at the earliest opportunity when the value in @XXX is neither "Yes" nor "No" so we can fix the underlying problem ... and not have it running wrongly for months and then have to fix the mess than has ensued through the whole database!! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-01-03 : 04:47:01
|
quote: Originally posted by Kristen Yes, you are quite right - its just my coding style Madhi We don't codeIF @XXX = 'Yes' THEN 1 ELSE 0 ENDever!!! because we want the application to "break" at the earliest opportunity when the value in @XXX is neither "Yes" nor "No" so we can fix the underlying problem ... and not have it running wrongly for months and then have to fix the mess than has ensued through the whole database!!
You are correct MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|