hi all
i have a table that contains patient complications. My ultimate goal is to create a report using reporting services that will display the complications. I want to create a list of complications seperated by ", ". I was trying to accomplish this using a function that would run through a patients record and if they have a complication store it in a variable and any subsequent complications would be added to the variable with a ", " so that the result would look like "compliation1, complications2..."
Here is what i have now.
Using just one varible was returning an error. Also if i eliminate all but one case statement the function will run. Does anyone have any ideas how to fix this or if there is another way to accomplish what i want. I could do the formatting in reporting services but would rather have it done in the stored procedure.
i have a table that contains patient complications. My ultimate goal is to create a report using reporting services that will display the complications. I want to create a list of complications seperated by ", ". I was trying to accomplish this using a function that would run through a patients record and if they have a complication store it in a variable and any subsequent complications would be added to the variable with a ", " so that the result would look like "compliation1, complications2..."
Here is what i have now.
Code:
create function dbo.MorbidityList
(@Casenum varchar(10))
returns varchar(200)
as
begin
declare @Complications varchar(200), @CompList varchar(300)
set @Complications =
(
select
case when O.Surg_Occl = 1
then
case when @CompList is null
then @CompList + 'Surgical Occlusion'
else @CompList + ', Surgical Occlusion'
end
else @CompList
end,
case when O.Surg_Bleed = 1
then
case when @CompList is null
then @CompList + 'Surgical Bleed'
else @CompList + ', Surgical Bleed'
end
else @CompList
end,
case when O.Surg_Device = 1
then
case when @CompList is null
then @CompList + 'Surgical Device'
else @CompList + ', Surgical Device'
end
else @CompList
end,
case when O.Other_Surg is not null
then
case when @CompList is null
then @CompList + O.Other_Surg
else @CompList + ', ' + O.Other_Surg
end
else @CompList
end
from
Outcomes O
where
@Casenum = O.Casenum
)
return @Complications
end