Question : Provide Current mm as @AsOfMonth and current yyyy as @AsOfYear

I have a function which calls another function to gather data. I want to execute it using reporting services. How to a set the @AsOfMonth and @AsOfYear so that it is whatever the current month/year is at the time of executing the function?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
ALTER FUNCTION [dbo].[PXQ7050_UDF]
    (
     @AsOfMonth AS VARCHAR(2)
    ,@AsOfYear AS VARCHAR(4)
    ,@GblOptState VARCHAR(4)
    )
RETURNS TABLE
AS
RETURN
    SELECT DISTINCT
            [Claim]
           ,[Claimant]
           ,[Insured]
           ,[Risk Name]
           ,[Indemnity Reserves]
           ,[Policy Eff Date]
    FROM    ( SELECT    LossRun.Claim
                       ,LossRun.Claimant
                       ,LossRun.Insured
                       ,LossRun.Risk AS [Risk Name]
                       ,LossRun.[Indem Reserve] AS [Indemnity Reserves]
                       ,LossRun.PolEffDate AS [Policy Eff Date]
              FROM      dbo.PXQ7000_UDF(@AsOfMonth, @AsOfYear, NULL, 0, 0, 0,
                                        @GblOptState) LossRun
            ) DTL
    WHERE   [Policy Eff Date] <= 07 / 01 / 2010
            AND [Indemnity Reserves] >= 300000.00

Answer : Provide Current mm as @AsOfMonth and current yyyy as @AsOfYear

Remove @AsOfMonth and @AsOfYear from the outer function's definition and use:

Year(GetDate()) or DatePart(Year, GetDate())
Month(GetDate()) or DatePart(Month, GetDate())

You can convert this to VARCHAR as needed, but would actually expect month and year values to be passed around as INT.

Random Solutions  
 
programming4us programming4us