Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL 2012 stored procedure help

$
0
0

I seem to be having problems with an SP, can someone assist to debug? The SP runs without error, but values are not written to the destination AnaHistory table.

USE [Summary]
GO
/****** Object:  StoredProcedure [dbo].[CopyLiveData]    Script Date: 2013/11/30 04:39:00 PM ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
/*************************************************************************************************** 
  Copy data from InSQL Live table into Summary AnaHistory
  Triggered by InSQL Event   
  Trigger: 1 - daily, 2 - hourly
  Furnace: 1 to 4, no of furnace
  Hourly trigger called within the same hour. Daily trigger called during next day.
  Tags must be in SummaryTags table with correct trigger and enabled=1
***************************************************************************************************/
ALTER procedure [dbo].[CopyLiveData]
	@iTrigger int,
	@iFurnace int
as 
BEGIN
	DECLARE @i int, 
		@iMaxRowsTags int,
		@noUpdated int,
		@iResolution int
	DECLARE @szTagCu varchar(50)
	DECLARE @iAdjustTime int
	DECLARE @szFurnace char(3)
	set nocount ON
	if (@iFurnace = 1)
	  select @szFurnace = 'F1%'
	if (@iFurnace = 2)
	  select @szFurnace = 'F2%'
	if (@iFurnace = 3)
	  select @szFurnace = 'F3%'
	if (@iFurnace = 4)
	  select @szFurnace = 'F4%'
	if (@iFurnace = 5)
	  select @szFurnace = 'BH%'
	DECLARE cuTags SCROLL CURSOR 
		FOR select Tagname from SummaryTags
		WHERE TriggerID = @iTrigger
		and tagname like @szFurnace
		and enabled = 1
	SELECT @iMaxRowsTags = count(*) FROM SummaryTags
	  WHERE TriggerID = @iTrigger
 	  and tagname like @szFurnace
	  and enabled = 1
	CREATE TABLE #AnalogHistoryTemp (
	  [DateTime] [datetime] NOT NULL ,
	  [TagName] [varchar] (33) NOT NULL ,
	  [Value] [real] NULL ,
	  [Quality] [tinyint] NOT NULL ,
	  [QualityDetail] [int] NULL ,
	  [wwTagKey] [int] NOT NULL 
	)
	OPEN cuTags
	SELECT  @i = 1
	FETCH FIRST FROM cuTags into @szTagCu
	WHILE (@i <= @iMaxRowsTags)
	BEGIN
	  /* select @szTagCu, @szActDT */
	  INSERT INTO #AnalogHistoryTemp	
	     select DateTime,Tagname,Value,Quality,QualityDetail,wwTagKey from Runtime..v_AnalogLive where tagname=@szTagCu
  	  FETCH NEXT FROM cuTags into @szTagCu
	  select @i = @i + 1	
	END
	CLOSE cuTags
	DEALLOCATE cuTags
	exec AdjustTime @iTrigger
	INSERT into AnaHistory
		SELECT Datetime, tagname, value, quality=0 from #AnalogHistoryTemp
	DROP TABLE #AnalogHistoryTemp
	set nocount OFF
--	select @noUpdated = count(*) from #AnalogHistoryTemp
--	select @noUpdated = @noUpdated / @iMaxRowsTags
/*	DELETE AnalogHistoryTemp*/
END


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>