-2

I am working on an SQL View which retrieves data from a View and an SQL table LastTrade and I use a webpage to insert data into the table LastTradeand when I insert a row I want my SQL view updated.

my View is as follows

CREATE VIEW [dbo].[CanadianCrudes]
AS
  SELECT a.Id,
         a.Product,
         a.Grade,
         a.Term,
         a.Pipeline,
         a.Location,
         a.[Index],
         a.bidvolume,
         a.Bidcp,
         a.Bid,
         a.Offer,
         a.offercp,
         a.offervolume,
         a.TermID,
         a.ProductID,
         a.GradeID,
         a.Locked,
         a.Hold,
         a.offercpid,
         a.bidcpid,
         a.idbid,
         a.[sequence],
         CASE
           WHEN ROW_NUMBER()
                  OVER (
                    PARTITION BY a.ProductID, a.GradeID, a.TermID, a.Pipeline, a.[Index]
                    ORDER BY a.Bid DESC, a.Offer) = 1 THEN b.LastTradeValue
           ELSE NULL
         END AS LastTradeValue
  FROM   CanadianCrudesRaw AS a
         LEFT JOIN (SELECT Product,
                           Grade,
                           Term,
                           Pipeline,
                           [Index],
                           MIN(LastTradeValue) LastTradeValue
                    FROM   LastTrades
                    GROUP  BY Product,
                              Grade,
                              Term,
                              Pipeline,
                              [Index]) AS b
                ON b.Product = a.Product
                   AND b.Grade = a.Grade
                   AND b.Term = a.Term
                   AND ISNULL(b.Pipeline, '00') = ISNULL(a.Pipeline, '00')
                   AND ISNULL(b.[Index], '00') = ISNULL(a.[Index], '00')

How do I implement a trigger which refreshes my view to get the inserted data?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
DoIt
  • 3,270
  • 9
  • 51
  • 103
  • 4
    No need for a trigger, mate - just SELECT from the view, and it'll pull whatever data is currently in your table. – AHiggins Dec 03 '14 at 19:33
  • 1
    This question appears to be off-topic because it is about updating a view, which is not actually a thing. – AHiggins Dec 03 '14 at 19:35

1 Answers1

0

just do the following query

SELECT * FROM [dbo].[CanadianCrudes]
Dudi Konfino
  • 1,126
  • 2
  • 13
  • 24