0

以为我已经解决了这个问题,但它又回来了!!试图消除我正在重构的存储过程上的最后一个光标。

我的问题是我没有将表中的列加载到游标中以链接到我的#UTM2 表以消除游标并将其全部带回一组。有解决方法吗???

 DECLARE @ChannelId INT, 
         @URLSignature Varchar(30), 
         @RawSQL VARCHAR(2000), 
         @SQLQuery VARCHAR(4000), 
         @ThisUTMId BIGINT  

 DECLARE cursChannels CURSOR STATIC 
     FOR 
     SELECT ChannelId, URLSignature, RawSQL  
     FROM dbo.TrackingChannel_tbl (NOLOCK)  
     WHERE ProcessVisitDate = 1  


  IF @URLSignature <> ''  
  SET @SQLQuery = @SQLQuery + 'AND u.RawURLRequest like ''%' + @URLSignature + '%'' '    

  IF @RawSQL <> ''  
  SET @SQLQuery = @SQLQuery + @RawSQL  

  EXEC (@SQLQuery)  


INSERT INTO dbo.TrackingChannelDailyTotal_tbl 
           (ChannelId, TrackingDate, Conversions, TotalMargin)  
SELECT @ChannelId, @ConvDate, Count(u1.trpUTMID), IsNUll(SUM(TotalMargin),0)  
FROM #UTM u1 
JOIN #UTM2 u2 
ON u1.TRputmid = u2.trputmid  

FETCH cursChannels INTO @ChannelId, @URLSignature, @RawSQL  

修正,如何填充#temp 表

        CREATE TABLE #UTM 
      (trpUTMID BIGINT PRIMARY KEY, 
       TotalMArgin MONEY, 
       RawURLRequest Varchar(2000), 
       Keywords VARCHAR(1000), VisitDate DATETIME, 
       RefererURL VARCHAR(2000))  


    INSERT INTO #UTM (trputmid, TotalMargin)  
       SELECT trpUTMID, SUM(b.TotalMArgin)  
       FROM TrackingConversion_tbl  c (NOLOCK) 
       JOIN  Booking_tbl b (NOLOCK)             
       ON c.BookingId = b.BookingId 
       WHERE
          c.bookedDate > @convDate 
       GROUP BY trputmid  

    UPDATE u  
       SET RawURLRequest = v.RawURLRequest,  
           Keywords = v.Keywords,  
           VisitDate = v.VisitDate,  
           RefererURL = v.RefererURL  
      FROM #UTM u,    
           TrackingVisit_tbl (NOLOCK)  v   
      WHERE v.trpUTMID = u.trpUTMId

希望取得成果

ChannelId  TrackingDate             Conversions  TotalMargin
---------  -----------------------  -----------  -----------
1          2012-03-14 00:00:00.000  0            0.00
2          2012-03-14 00:00:00.000  22           557.0296
3          2012-03-14 00:00:00.000  0            0.00

直到当前日期的每一天或 41 个频道

4

0 回答 0