Pregunta

I tried to execute this procedure but I am getting error.

I tried to execute using:

execute Currentmonth 20141220 

Error:

Msg 208, Level 16, State 1, Procedure Currentmonth, Line 15
Invalid object name 'DimDate'

Why I am getting this error? Can you please tell me the errors in the query for creating stored procedure and what are the parameters I am expecting?

create procedure Currentmonth
    @Completeddatekey varchar(20)
as
   begin

Getting the current date and formatting it

    Declare @currentdate varchar(30)
        set @currentdate = convert(Varchar(20), getdate()-1, 101)
    print @currentdate

Getting DayofMonth and EndofMonth from DimDate

     Declare @dayofmonth int
     Declare @endofmonth int

     select @dayofmonth = DayofMonth, @endofmonth = EndofMonthDateKey 
     from bi.dbo.DimDate
     where datekey = @currentdate

Getting HierMonthEndKey

     declare @hiermonthendkey int

     select @hiermonthendkey = MAX(HierMonthEndKey) 
     from DimHospiceHiearchy
     where HierMonthEndKey <= @currentdate+1

Declare @day

For Loop
     Declare @i int = 0
     declare @startdate varchar(20)
     select @startdate = CAST(CAST(YEAR(convert(Varchar(20), getdate()-1, 101)) AS VARCHAR(4)) 
     + '/' + CAST(MONTH(convert(Varchar(20), getdate()-1, 101)) AS VARCHAR(2)) + '/01'  AS DATETIME)+1

      While @i <=@dayofmonth
      begin
        set @startdate = @startdate+@i
        exec MA010103 @completeddatekey, @hiermonthendkey 
        set @i = @i+1
     end
   end

No hay solución correcta

Otros consejos

This error occurs when an object that does not exist is referenced. If the object exists, you might need to include the owner's name in the object name.

Please check the table exists in the mentioned database ?

select @dayofmonth = DayofMonth, @endofmonth = EndofMonthDateKey from bi.dbo.DimDate where datekey = @currentdate

Instead of

  Declare @dayofmonth int
 Declare @endofmonth int
 select @dayofmonth = DayofMonth, @endofmonth = EndofMonthDateKey from  bi.dbo.DimDate
   where datekey = @currentdate

Please try

  Declare @dayofmonth int
 Declare @endofmonth int
 select @dayofmonth = DayofMonth, @endofmonth = EndofMonthDateKey from  DimDate
   where datekey = @currentdate

Or check if DimDate Table exists

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top