0
SQL 2000で既存のSPROCを変更しようとしています。元のSPROCはカーソルの一部としてFuncViewを使用していました。新しいレポートはカーソルを必要としませんが、カーソル・ステートメントの外でFuncViewを実行する方法がわかりません。以下の最初の例は、元のコードのカーソル部分です。 2番目は私の修正です....結果のエラーメッセージです。助けてください...ストアドプロシージャ内でのFuncViewの実行
DECLARE @FuncView_PlantConditionAssessmentMetrics VARCHAR(8000)
DECLARE FuncView_PlantConditionAssessmentMetricsCursor CURSOR FOR
Select
'UPDATE #rsTemp
SET TotalComponentsOnTask = rsMetric.TotalComponentsOnTask,
TotalComponentsAssessedMeasured = rsMetric.TotalComponentsAssessedMeasured,
TotalComponentsNotMeasured = rsMetric.TotalComponentsNotMeasured,
TotalComponentsAssessedNotMeasured = rsMetric.TotalComponentsAssessedNotMeasured,
OverdueElevatedItems = rsMetric.OverdueElevatedItems,
OverdueAdvisoryItems = rsMetric.OverdueAdvisoryItems
FROM ['+DBCatalog+'].[dbo].FuncView_PlantConditionAssessmentMetrics ('''+CONVERT(varchar(50), @StartDate, 100)+''','''+ CONVERT(varchar(50), @EndDate, 100)+''') rsMetric
WHERE DBCatalog = '''+DBCatalog+''''
FROM [HostedTangoSettingsSQL].[dbo].[DatabaseTable]
WHERE CustomerID = @CustomerID
AND
HostedDBTypeID IN (SELECT HostedDBTypeID FROM [HostedTangoSettingsSQL].[dbo].defs_HostedDBTypes
WHERE IsActiveDatabase = 1 AND HostedDBTypeID <> 3)
OPEN FuncView_PlantConditionAssessmentMetricsCursor
FETCH NEXT FROM FuncView_PlantConditionAssessmentMetricsCursor INTO @FuncView_PlantConditionAssessmentMetrics
WHILE (@@fetch_status <> -1)
BEGIN
EXEC(@FuncView_PlantConditionAssessmentMetrics)
FETCH NEXT FROM FuncView_PlantConditionAssessmentMetricsCursor INTO @FuncView_PlantConditionAssessmentMetrics
END
CLOSE FuncView_PlantConditionAssessmentMetricsCursor
DEALLOCATE FuncView_PlantConditionAssessmentMetricsCursor
DECLARE @FuncView_PlantConditionAssessmentMetrics VARCHAR(8000)
SELECT FuncView_PlantConditionAssessmentMetrics = @FuncView_PlantConditionAssessmentMetrics
'UPDATE #rsTemp
SET TotalComponentsOnTask = rsMetric.TotalComponentsOnTask,
TotalComponentsAssessedMeasured = rsMetric.TotalComponentsAssessedMeasured,
TotalComponentsNotMeasured = rsMetric.TotalComponentsNotMeasured,
TotalComponentsAssessedNotMeasured = rsMetric.TotalComponentsAssessedNotMeasured,
OverdueElevatedItems = rsMetric.OverdueElevatedItems,
OverdueAdvisoryItems = rsMetric.OverdueAdvisoryItems
FROM ['[email protected]+'].[dbo].FuncView_PlantConditionAssessmentMetrics ('''+CONVERT(varchar(50), @StartDate, 100)+''','''+ CONVERT(varchar(50), @EndDate, 100)+''') rsMetric
WHERE DBCatalog = '''[email protected]+''''
Server: Msg 170, Level 15, State 1, Procedure UDR_PlantConditionAssessmentMetrics, Line 54
Line 54: Incorrect syntax near 'UPDATE #rsTemp
SET TotalComponentsOnTask = rsMetric.TotalComponentsOnTask,
TotalComponentsAssessedMeasured = rsMetric.To'.
「FuncView」とは何ですか? SQL Serverにはこのような用語はありません。 – RBarryYoung
私はそれが実際には奇妙な名前を持つテーブル値の関数だと思います – MartW