You are on page 1of 2

USE [BoursaKuwaitQueryNotifications]

GO

/****** Object: Table [dbo].[qn_query_notifications] Script Date: 3/22/2020


10:06:14 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[qn_query_notifications_temp](


[record_id] [bigint] IDENTITY(1,1) NOT NULL,
[message] [nvarchar](max) NULL,
[cat] [nvarchar](50) NULL,
[date] [datetime] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

------------------------------------------

USE [BK_WebMD2]
GO

/****** Object: Trigger [dbo].[QueryNotifications_1] Script Date: 3/22/2020


10:06:54 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER TRIGGER [dbo].[QueryNotifications_1]


ON [dbo].[StockQuotation]
FOR UPDATE
AS

IF UPDATE([Last]) OR UPDATE([Bid]) OR UPDATE([Change]) OR


UPDATE([ChangePerc]) OR UPDATE([Ask]) OR UPDATE([Open]) OR UPDATE([High]) OR
UPDATE([Low]) OR UPDATE([Vol]) OR UPDATE([Deal]) OR UPDATE([Amt])

BEGIN

BEGIN
SET NOCOUNT ON
DECLARE @message NVARCHAR(MAX)
SET @message = N'<root/>'

DECLARE @retvalOUT NVARCHAR(MAX)

SET @retvalOUT = (SELECT [Row],[Last],[Tim],[Bid],[Ask],[Open],[High],[Low],


[Vol],[Deal],[Amt],[VolA],[Prev],[DatP],[Scroll],[Ref],[HiL],[LoL],[OLLast],
[OLTim],[OLVol],[OLDeal],[OLAmt],[Assess],[Change],[ChangePerc],[InhState],
[W52High],[W52Low],[ExpPrice],[SettPrice],[SettPriceType],[UPrevClose],
[OfferDepth],[BidDepth],[offMktVolumeToday],[offMktValueToday],[WAPrice],
[OfferDepthClose],[BidDepthClose],[BidClose],[AskClose],[Instrument],[BoardId],
[minPriceStepArrId],[refMoveUpStepArrId],[refMoveDownStepArrId],[cbLowerLimit],
[cbUpperLimit],[changeRefPrice],[changeCBRefPrice],[changePercentRefPrice],
[OpenRefPrice],[AddDate],[ModDate], [sessionNameE], [sessionNameA], CASE When
[ChangePerc] > 0 Then '1' When [ChangePerc] < 0 Then '0' End as hl
FROM INSERTED
FOR XML PATH('row'), ROOT ('inserted'))

IF (@retvalOUT IS NOT NULL)


BEGIN SET @message = N'<root>' + @retvalOUT END

SET @retvalOUT = (SELECT [Row],[Last],[Tim],[Bid],[Ask],[Open],[High],[Low],


[Vol],[Deal],[Amt],[VolA],[Prev],[DatP],[Scroll],[Ref],[HiL],[LoL],[OLLast],
[OLTim],[OLVol],[OLDeal],[OLAmt],[Assess],[Change],[ChangePerc],[InhState],
[W52High],[W52Low],[ExpPrice],[SettPrice],[SettPriceType],[UPrevClose],
[OfferDepth],[BidDepth],[offMktVolumeToday],[offMktValueToday],[WAPrice],
[OfferDepthClose],[BidDepthClose],[BidClose],[AskClose],[Instrument],[BoardId],
[minPriceStepArrId],[refMoveUpStepArrId],[refMoveDownStepArrId],[cbLowerLimit],
[cbUpperLimit],[changeRefPrice],[changeCBRefPrice],[changePercentRefPrice],
[OpenRefPrice],[AddDate],[ModDate], [sessionNameE], [sessionNameA], CASE When
[ChangePerc] > 0 Then '1' When [ChangePerc] < 0 Then '0' End as hl
FROM DELETED
FOR XML PATH('row'), ROOT ('deleted'))

IF (@retvalOUT IS NOT NULL)


BEGIN
IF (@message = N'<root/>') BEGIN SET @message = N'<root>' + @retvalOUT END
ELSE BEGIN SET @message = @message + @retvalOUT END
END

IF (@message != N'<root/>') BEGIN SET @message = @message + N'</root>' END

IF (@message != N'<root/>')
BEGIN
INSERT INTO [BoursaKuwaitQueryNotifications].[dbo].
[qn_query_notifications] ([message], [cat], [date])
VALUES (@message, 'StockQuotation', GETDATE())

-- Temperary table
INSERT INTO [BoursaKuwaitQueryNotifications].[dbo].
[qn_query_notifications_temp] ([message], [cat], [date])
VALUES (@message, 'StockQuotation', GETDATE())

END
END

END

GO

You might also like