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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Pls anyone findout the output

Author  Topic 

vaans
Starting Member

3 Posts

Posted - 2013-12-13 : 04:38:38
alter function anf
(
@mdvn int,
@fdate datetime,
@tdate datetime
)
returns int
as
begin
declare @anvisitfun int
declare @vdate date
declare @fedddate date
declare @tedddate date
declare @tvdate date
set @vdate=dateadd(dd,-91,@fdate)
set @tvdate=dateadd(dd,36,@tdate)
set @fedddate=dateadd(dd,20,@fdate)
set @tedddate=dateadd(dd,310,@tdate)
declare @REGDT int
declare @ANC int
declare @TT1 int
declare @TT2 int
declare @IFA int
declare @BP int
declare @HB int

declare funcurz cursor static for
select dvn_cd,phc_cd,hsc_cd,sum(REGDT) as Regdt,SUM(ANC) as ANC,SUM(TT1) as TT1, SUM(TT2)as TT2,
SUM(IFA) as IFA, SUM(BP) as BP, SUM(HB) as HB from
(
select dvn_cd,phc_cd,hsc_cd,
case when ANEDD IS null then 0 else 1 end as REGDT,
case when visit_no=3 and ANEDD between @vdate and @tvdate then 1 else 0 end as ANC,
case when TTB=1 and ANEDD between @fdate and @tdate then 1 else 0 end as TT1,
case when TTB>2 and ANEDD between @fdate and @tdate then 1 else 0 end as TT2,
case when IFA=100 and ANEDD between @fdate and @tdate then 1 else 0 end as IFA,
case when BP>='140/90' and ANEDD between @fdate and @tdate then 1 else 0 end as BP,
case when HB<11 and ANEDD between @fdate and @tdate then 1 else 0 end as HB
from ANVisits3 a where DVN_CD=@mdvn and ANEDD between @fedddate and @tedddate
)a group by dvn_cd,phc_cd,hsc_cd
open funcurz
begin
fetch next from funcurz into @mdvn,@REGDT,@ANC,@TT1,@TT2,@IFA,@BP,@HB
while @@FETCH_STATUS=0
begin
print 'DVN : '+ convert(varchar(20),@mdvn)+',FDT :'+convert(varchar(20),@fdate)+
',TDT :'+convert(varchar(20),@tdate)+',RGDT:'+convert(varchar(20),@REGDT)+
',ANC :'+convert(varchar(20),@ANC)+',TT1 :'+convert(varchar(20),@TT1)+
',TT2 :'+convert(varchar(20),@TT2)+',IFA :'+convert(varchar(20),@IFA)+
',BP :'+convert(varchar(20),@BP)+',HB:'+ convert(varchar(20),@HB)
fetch next from funcurz into @mdvn,@REGDT,@ANC,@TT1,@TT2,@IFA,@BP,@HB
END
end
close funcurz
deallocate funcurz
return (@anvisitfun)
end
---------------------
Error shown as.
Msg 443, Level 16, State 14, Procedure anf, Line 46
Invalid use of a side-effecting operator 'PRINT' within a function.



vaans

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-13 : 06:57:24
You cant use print within a scalar function. you need to call function inside proc and then use print to print the return value if you want.
ALsternatively make it a stored procedure.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

vaans
Starting Member

3 Posts

Posted - 2013-12-16 : 05:19:00
pls sir correct the pgm and display the result to this coding


vaans
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-16 : 05:44:00
How can someone help without knowing what you're trying to do
Your current code doesnt make any sense to me.
Post some sample data and explain what you want giving the desired output. Otherwise nobody would be able to help you out!

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -