Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 10045

Custom Code in SSRS 2008

$
0
0

Hi,

I am trying to write Custom Code in SSRS for Age Calculation for two requirements in the same report,But report is giving error #Error in expression with my below code.

whole logic is same for both but only two lines are different,Do i need create two functions or can i use them in one function.Please guide me.

1)Age in Years (Ex: 4)

2) Age in Years + months (ex: 3 Years 6 months)

My SSRS Custom Code:

Public Shared Dim Years as Integer
Public Shared Dim Months as Integer
Public Shared Dim Days as Integer
Public Shared Dim Age as Integer

Public Shared Function CalAge(ByVal D1 As Datetime,ByVal D2 As Datetime ) As Integer
  Years=Year(D1)-Year(D2)
  Months=Month(D1)-Month(D2)
  Days=Day(D1)-Day(D2)
       If Days < 0 then 
           Months=Months-1
         End if
       If Months < 0 then 
          Years=Years-1
         End if
       If Months < 0 then
          Months=Months+12
       End If
     Return Years 

If Months=1 then
    Age=Years+" Years " + Months + "Month"
else
  Age=Years+" Years " + Months + "Months" 

End If 

Return Age

  End Function




Viewing all articles
Browse latest Browse all 10045

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>