stuck in a sql query

Farhan Jamil 421 Reputation points
2021-04-01T09:12:28.787+00:00

Hi All

Not sure where I am going wrong. Any assistance will be off great help

I am trying to run a stored procedure against a cursor which will insert a one year record into a table

This is my SQL query:-

declare @TxnDate Date
declare cur Cursor local for
select cast(Date_fld as date) from dbo.Calendar where cast(date_fld as date) between '2020-01-26' and '2021-01-30'
open cur
fetch next from cur into @TxnDate

While @@FETCH_STATUS = 0  
Begin  
      
    insert into [dbo].ONLINEFY2020   
	Exec dbo.[ONLINE_IMPORT] @TxnDate  
      
Fetch next from cur into @TxnDate  
End  

close cur
deallocate cur

Here is my table definition

83615-image.png

and here is the error i am getting

83560-image.png

Any assistance is appreciated

Thanks
Farhan Jamil

Developer technologies Transact-SQL
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2021-04-01T10:28:15.263+00:00

    Try this too:

    insert into [dbo].ONLINEFY2020 
    exec dbo.[ONLINE_IMPORT] @date = @TxnDate
    

1 additional answer

Sort by: Most helpful
  1. Olaf Helper 47,436 Reputation points
    2021-04-01T10:18:45.687+00:00

    select cast(Date_fld as date)

    The column name "Date_fld" don't match with the table definition/don't exist.
    So it's from a different table and by the error message it's type "integer", right?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.