大家好,是的,来自较早问题的同一个人......在游标/SQL方面我真的很糟糕我一直在使用我制作的以下存储过程/游标..它编译正确,当我出现问题时尝试执行它我得到这个错误:
消息 208,级别 16,状态 1,第 1 行无效的对象名称“DQM.dbo.ST_0043_BLANK_CONSENT_SAP_SIEBEL”。
(0 行受影响)消息 208,级别 16,状态 1,第 1 行无效的对象名称“DQM.dbo.ST_0044_CONSENT_SIEBEL_SAP_DIFF”。
(0 行受影响)消息 208,级别 16,状态 1,第 1 行无效的对象名称“DQM.dbo.ST_0045_CONSENT_SIEBEL_BANNER_DIFF”。
现在我知道所有这些对象都存在,因为当我全选时,我会返回行。任何帮助,将不胜感激。
USE [Adhoc_datafix]
GO
/****** Object: StoredProcedure [dbo].[CostTest_02] Script Date: 01/10/2013 15:43:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[CostTest_02]
AS
BEGIN
DECLARE @Issue_id int;
DECLARE @Master_id int;
DECLARE @Issue_table varchar(255);
DECLARE @price real;
DECLARE @rowcount bigint;
DECLARE @sql varchar(3000)
DECLARE cost_cursor cursor FOR
SELECT [Issue Id], [Master Issue Id], [Issue Table], [Price]
from Adhoc_datafix..[IssueTable]
FOR UPDATE OF [Issue Id];
OPEN cost_cursor;
FETCH NEXT FROM cost_cursor into @Issue_ID, @Master_id, @Issue_table, @Price
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @sql = 'Select count(*) from DQM.' + quotename(@Issue_table)
EXEC(@sql)
set @Rowcount = @@rowcount
UPDATE ADHOC_DATAFIX..[Issue Cost]
set [Issue Id] = @Issue_ID ,
[Master Issue Id] = @Master_ID ,
[Row Count] = @Rowcount,
[Cost] = CAST(@Rowcount * @price as money)
--WHERE CURRENT OF cost_cursor;
FETCH NEXT FROM cost_cursor into @Issue_ID, @Master_id, @Issue_table, @Price
END
close cost_cursor;
DEALLOCATE cost_cursor;
END