SayeyeZohor
سه شنبه 17 مرداد 1391, 17:32 عصر
Create Function Fn_SickHoof(@Mp int,@Milk int,@st char(30),@I int)
returns int
as
begin
Declare @Res int
Set
@Res= Case When @I=1 then
(case when ltrim(Rtrim(@St))='InfFlag' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and InfFlag=1)
when ltrim(Rtrim(@St))='InfFinger' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and InfFinger=1)
when ltrim(Rtrim(@St))='InfDerma' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and InfDerma=1)
when ltrim(Rtrim(@St))='InfWhole' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and InfWhole=1)
when ltrim(Rtrim(@St))='InfAcid' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and InfAcid=1)
when ltrim(Rtrim(@St))='WInfWhite' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfWhite=1)
when ltrim(Rtrim(@St))='WInfLam' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfLam=1)
when ltrim(Rtrim(@St))='WInfTarak' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfTarak=1)
when ltrim(Rtrim(@St))='WInfSayesh' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfSayesh=1)
when ltrim(Rtrim(@St))='WInfAbPashne' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfAbPashne=1)
when ltrim(Rtrim(@St))='WInfInjectPashne' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfInjectPashne=1)
when ltrim(Rtrim(@St))='WInfAbKaf' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfAbKaf=1)
when ltrim(Rtrim(@St))='WInfInjectKaf' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfInjectKaf=1)
when ltrim(Rtrim(@St))='WInfOutObject' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfOutObject=1)
when ltrim(Rtrim(@St))='WInfSeprate' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfSeprate=1)
when ltrim(Rtrim(@St))='WInfVertical' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfVertical=1)
when ltrim(Rtrim(@St))='WInfSoftKaf' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfSoftKaf=1)
when ltrim(Rtrim(@St))='WInfTwoLayer' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfTwoLayer=1)
when ltrim(Rtrim(@St))='WInfStone' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfStone=1)
when ltrim(Rtrim(@St))='SecGach' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecGach=1)
when ltrim(Rtrim(@St))='SecYellow' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecYellow=1)
when ltrim(Rtrim(@St))='SecPoint' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecPoint=1)
when ltrim(Rtrim(@St))='SecNotPoint' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecNotpoint=1)
when ltrim(Rtrim(@St))='SecChange' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecChange=1)
when ltrim(Rtrim(@St))='SecError' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecError=1)
when ltrim(Rtrim(@St))='SecUnHoof' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecUnHoof=1)
when ltrim(Rtrim(@St))='SecDamage' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecDamage=1)
when ltrim(Rtrim(@St))='SecSafe' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecSafe=1)
end)
else
(case when ltrim(Rtrim(@St))='InfFlag' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and InfFlag=1)
when ltrim(Rtrim(@St))='InfFinger' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and InfFinger=1)
when ltrim(Rtrim(@St))='InfDerma' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and InfDerma=1)
when ltrim(Rtrim(@St))='InfWhole' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and InfWhole=1)
when ltrim(Rtrim(@St))='InfAcid' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and InfAcid=1)
when ltrim(Rtrim(@St))='WInfWhite' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfWhite=1)
when ltrim(Rtrim(@St))='WInfLam' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfLam=1)
when ltrim(Rtrim(@St))='WInfTarak' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfTarak=1)
when ltrim(Rtrim(@St))='WInfSayesh' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfSayesh=1)
when ltrim(Rtrim(@St))='WInfAbPashne' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfAbPashne=1)
when ltrim(Rtrim(@St))='WInfInjectPashne' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfInjectPashne=1)
when ltrim(Rtrim(@St))='WInfAbKaf' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfAbKaf=1)
when ltrim(Rtrim(@St))='WInfInjectKaf' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfInjectKaf=1)
when ltrim(Rtrim(@St))='WInfOutObject' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfOutObject=1)
when ltrim(Rtrim(@St))='WInfSeprate' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfSeprate=1)
when ltrim(Rtrim(@St))='WInfVertical' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfVertical=1)
when ltrim(Rtrim(@St))='WInfSoftKaf' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfSoftKaf=1)
when ltrim(Rtrim(@St))='WInfTwoLayer' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfTwoLayer=1)
when ltrim(Rtrim(@St))='WInfStone' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfStone=1)
when ltrim(Rtrim(@St))='SecGach' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecGach=1)
when ltrim(Rtrim(@St))='SecYellow' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecYellow=1)
when ltrim(Rtrim(@St))='SecPoint' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecPoint=1)
when ltrim(Rtrim(@St))='SecNotPoint' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecNotpoint=1)
when ltrim(Rtrim(@St))='SecChange' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecChange=1)
when ltrim(Rtrim(@St))='SecError' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecError=1)
when ltrim(Rtrim(@St))='SecUnHoof' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecUnHoof=1)
when ltrim(Rtrim(@St))='SecDamage' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecDamage=1)
when ltrim(Rtrim(@St))='SecSafe' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecSafe=1)
end)
end
return @Res
end
اين فانكشن من هستش تو اسكيوال
حالا ميخوام با نوشتن يك كوئري اين دستور رو پيدا كنم
اين كار رو با اين دستور انجام دادم
مشكل اينجاست كه متن رو كامل نشون نمي ده
SELECT ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE (objectproperty(object_id(ROUTINE_NAME),'IsMSShipp ed') = 0) AND (ROUTINE_TYPE ='FUNCTION') AND (ROUTINE_NAME = 'Fn_SickHoof') ORDER BY ROUTINE_NAME
كمك :گریه:
returns int
as
begin
Declare @Res int
Set
@Res= Case When @I=1 then
(case when ltrim(Rtrim(@St))='InfFlag' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and InfFlag=1)
when ltrim(Rtrim(@St))='InfFinger' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and InfFinger=1)
when ltrim(Rtrim(@St))='InfDerma' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and InfDerma=1)
when ltrim(Rtrim(@St))='InfWhole' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and InfWhole=1)
when ltrim(Rtrim(@St))='InfAcid' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and InfAcid=1)
when ltrim(Rtrim(@St))='WInfWhite' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfWhite=1)
when ltrim(Rtrim(@St))='WInfLam' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfLam=1)
when ltrim(Rtrim(@St))='WInfTarak' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfTarak=1)
when ltrim(Rtrim(@St))='WInfSayesh' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfSayesh=1)
when ltrim(Rtrim(@St))='WInfAbPashne' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfAbPashne=1)
when ltrim(Rtrim(@St))='WInfInjectPashne' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfInjectPashne=1)
when ltrim(Rtrim(@St))='WInfAbKaf' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfAbKaf=1)
when ltrim(Rtrim(@St))='WInfInjectKaf' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfInjectKaf=1)
when ltrim(Rtrim(@St))='WInfOutObject' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfOutObject=1)
when ltrim(Rtrim(@St))='WInfSeprate' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfSeprate=1)
when ltrim(Rtrim(@St))='WInfVertical' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfVertical=1)
when ltrim(Rtrim(@St))='WInfSoftKaf' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfSoftKaf=1)
when ltrim(Rtrim(@St))='WInfTwoLayer' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfTwoLayer=1)
when ltrim(Rtrim(@St))='WInfStone' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and WInfStone=1)
when ltrim(Rtrim(@St))='SecGach' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecGach=1)
when ltrim(Rtrim(@St))='SecYellow' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecYellow=1)
when ltrim(Rtrim(@St))='SecPoint' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecPoint=1)
when ltrim(Rtrim(@St))='SecNotPoint' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecNotpoint=1)
when ltrim(Rtrim(@St))='SecChange' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecChange=1)
when ltrim(Rtrim(@St))='SecError' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecError=1)
when ltrim(Rtrim(@St))='SecUnHoof' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecUnHoof=1)
when ltrim(Rtrim(@St))='SecDamage' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecDamage=1)
when ltrim(Rtrim(@St))='SecSafe' then
(Select Sum(CountSerial) From VwSickHoof1 Where MilkPeriod=@Mp and Milk=@Milk and SecSafe=1)
end)
else
(case when ltrim(Rtrim(@St))='InfFlag' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and InfFlag=1)
when ltrim(Rtrim(@St))='InfFinger' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and InfFinger=1)
when ltrim(Rtrim(@St))='InfDerma' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and InfDerma=1)
when ltrim(Rtrim(@St))='InfWhole' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and InfWhole=1)
when ltrim(Rtrim(@St))='InfAcid' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and InfAcid=1)
when ltrim(Rtrim(@St))='WInfWhite' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfWhite=1)
when ltrim(Rtrim(@St))='WInfLam' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfLam=1)
when ltrim(Rtrim(@St))='WInfTarak' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfTarak=1)
when ltrim(Rtrim(@St))='WInfSayesh' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfSayesh=1)
when ltrim(Rtrim(@St))='WInfAbPashne' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfAbPashne=1)
when ltrim(Rtrim(@St))='WInfInjectPashne' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfInjectPashne=1)
when ltrim(Rtrim(@St))='WInfAbKaf' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfAbKaf=1)
when ltrim(Rtrim(@St))='WInfInjectKaf' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfInjectKaf=1)
when ltrim(Rtrim(@St))='WInfOutObject' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfOutObject=1)
when ltrim(Rtrim(@St))='WInfSeprate' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfSeprate=1)
when ltrim(Rtrim(@St))='WInfVertical' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfVertical=1)
when ltrim(Rtrim(@St))='WInfSoftKaf' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfSoftKaf=1)
when ltrim(Rtrim(@St))='WInfTwoLayer' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfTwoLayer=1)
when ltrim(Rtrim(@St))='WInfStone' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and WInfStone=1)
when ltrim(Rtrim(@St))='SecGach' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecGach=1)
when ltrim(Rtrim(@St))='SecYellow' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecYellow=1)
when ltrim(Rtrim(@St))='SecPoint' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecPoint=1)
when ltrim(Rtrim(@St))='SecNotPoint' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecNotpoint=1)
when ltrim(Rtrim(@St))='SecChange' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecChange=1)
when ltrim(Rtrim(@St))='SecError' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecError=1)
when ltrim(Rtrim(@St))='SecUnHoof' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecUnHoof=1)
when ltrim(Rtrim(@St))='SecDamage' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecDamage=1)
when ltrim(Rtrim(@St))='SecSafe' then
(Select Sum(CountSerial) From VwSickHoof2 Where MilkPeriod=@Mp and Milk=@Milk and SecSafe=1)
end)
end
return @Res
end
اين فانكشن من هستش تو اسكيوال
حالا ميخوام با نوشتن يك كوئري اين دستور رو پيدا كنم
اين كار رو با اين دستور انجام دادم
مشكل اينجاست كه متن رو كامل نشون نمي ده
SELECT ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE (objectproperty(object_id(ROUTINE_NAME),'IsMSShipp ed') = 0) AND (ROUTINE_TYPE ='FUNCTION') AND (ROUTINE_NAME = 'Fn_SickHoof') ORDER BY ROUTINE_NAME
كمك :گریه: