Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.45 KB | None | 0 0
  1.  
  2.                         update sc
  3.                             set [cnt] = cb.cnt,
  4.                                 [date] = cb.[date]
  5.                             from subscriber_counters_buffer cb
  6.                                 inner join subscriber_counters sc on sc.subscriber_id = cb.subscriber_id
  7.                                                                  and sc.period_type_id = cb.period_type_id
  8.                                                                  and sc.channel = cb.Channel
  9.                                                                  and sc.counter_type = cb.counter_type
  10.                        
  11.                         if(@@ROWCOUNT != (select count(*) from subscriber_counters_buffer))
  12.                         begin
  13.                             insert into subscriber_counters
  14.                                 select cb.subscriber_id, cb.period_type_id, cb.channel, cb.[cnt], cb.[date], cb.counter_type
  15.                                     from subscriber_counters_buffer cb
  16.                                     where not exists
  17.                                     ( select 1
  18.                                         from subscriber_counters sc
  19.                                         where sc.subscriber_id = cb.subscriber_id
  20.                                           and sc.period_type_id = cb.period_type_id
  21.                                           and sc.channel = cb.Channel
  22.                                           and sc.counter_type = cb.counter_type  
  23.                                     )
  24.                         end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement