我需要標量轉換成內聯函數如何將標量轉化爲內聯函數的SQL Server 2008
我的標量函數
create function [dbo].[fun_functional_score] (@phy_id varchar(20))
returns varchar(50)
as
begin
declare @level_initial int, @level_current int
-- initial functional score
set @level_initial=(SELECT pflag.fun_level
FROM tbl_phy_demographic_details as [phy]
inner join tbl_all_purple_flag_level as [pflag] on phy.Demographic_id=pflag.Id
WHERE phy.Physicion_id= @phy_id
and pflag.visited_count in (select MAX(visited_count)-1 from tbl_all_purple_flag_level group by id))
-- current functional score
set @level_current=(SELECT pflag.fun_level
FROM tbl_phy_demographic_details as [phy]
inner join tbl_all_purple_flag_level as [pflag] on phy.Demographic_id=pflag.Id
WHERE [email protected]_id
and pflag.visited_count in (select MAX(visited_count) from tbl_all_purple_flag_level group by id))
-- current functional scor
--set @level_current=(SELECT pflag.fun_level
-- FROM tbl_phy_demographic_details as [phy]
--to calculate functional score
declare @fun_level varchar(20),@result varchar(50)
set @[email protected][email protected]_initial;
if @fun_level = 0 set @result='Maintained'
if @fun_level = '-1' set @result='Minor Improvement'
if @fun_level = '-2' set @result='Moderate Improvement'
if @fun_level = '-3' set @result='Significant Improvement'
if @fun_level = '-4' set @result='Substantial Improvement'
if @fun_level = '1' set @result='Minor Reduction'
if @fun_level = '2' set @result='Moderate Reduction'
if @fun_level = '3' set @result='Significant Reduction'
if @fun_level = '4' set @result='Substantial Reduction'
return @result
end
這是可能的嗎?
請不要用[tag:mysql]標記SQL Server問題。 「MySQL」並不意味着「我當前的SQL Server問題」... –
你是否試圖問你同一個問題,你有早些發佈http://stackoverflow.com/questions/21046294/how-to-return-multilpe- values-from-function-sql-server? – Sachin
是的,有一些錯誤,這是更新的代碼。現在我需要轉換成內聯函數? – Happy