Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT NULL AS msg_id, NULL AS total, NULL AS found
- FROM dual
- WHERE (
- @total :=0
- OR
- @found :=0
- )
- UNION
- SELECT msg_id, @total AS total, @found :=1 AS found
- FROM messages_queue
- WHERE (
- @total := @total + rcpts_count
- )
- AND @total <1000
- UNION
- SELECT msg_id, rcpts_count AS total, 0 AS found
- FROM messages_queue
- WHERE IF( @found =0, @found :=1, 0 )
- -- sample table
- create table x
- (col1 int identity(1, 1)
- ,col2 varchar(50))
- -- sample data
- insert into x (col2) values
- (null)
- ,(null)
- ,(null)
- ,(null)
- ,(null)
- -- update from select
- update x
- set x.col2 = 'even'
- from x as [t2]
- where
- col1 = t2.col1
- and t2.col1 % 2 = 0
- -- show results
- select * from x
- -- clean up
- drop table x
- UPDATE message_queue mq
- INNER JOIN (
- SELECT NULL AS msg_id, NULL AS total, NULL AS found
- FROM dual
- WHERE (
- @total :=0
- OR
- @found :=0
- )
- UNION
- SELECT msg_id, @total AS total, @found :=1 AS found
- FROM messages_queue
- WHERE (
- @total := @total + rcpts_count
- )
- AND @total <1000
- UNION
- SELECT msg_id, rcpts_count AS total, 0 AS found
- FROM messages_queue
- WHERE IF( @found =0, @found :=1, 0 )
- ) msgs ON msgs.msg_id = mq.msg_id
- SET mq.fet_id = 12345;
Add Comment
Please, Sign In to add comment