I'm trying to run a stored procedure. In the SP I create two table variables (by using 3 CTE's). Then join the two tables and INSERT INTO an existing table. I keep getting the error CANNOT OBTAIN A LOCK RESOURCE. Any ideas how I can fix this? Is it the way I wrote my SP?
ALTER PROCEDURE [dbo].[CreateDailyAttribution]
-- Add the parameters for the stored procedure here
@day1 varchar(10)
,@day2 varchar(10)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @tableUnrealized as table
(
POFFIC varchar(3)
,PACCT varchar(5)
--,PATYPE varchar(3)
,PSDSC1 varchar(100)
,ShortDesc varchar(100)
,ChangeInOTE decimal(18,0)
,tMinus1_Qty integer
,tMinus2_Qty integer
,Sector varchar(50)
);
DECLARE @tableRealized as table
(
POFFIC varchar(3)
,PACCT varchar(5)
--,PATYPE varchar(3)
,PSDSC1 varchar(100)
,ShortDesc varchar(100)
,Realized decimal(18,0)
,Sector varchar(50)
);