Примеры пользовательских процедур — различия между версиями
Материал из Oktell
(Новая страница: «Наверх <pre> if (@idtask = 'B8A22910-BFA4-480D-BFB1-151D0C06F93B') begin select @Id = operatorid from TableMain where Id = @…») |
(нет различий)
|
Версия 11:15, 19 декабря 2014
if (@idtask = 'B8A22910-BFA4-480D-BFB1-151D0C06F93B') begin select @Id = operatorid from TableMain where Id = @idabonent if (@Id is null) begin select u.Id from A_Users u inner join A_UserParams up on u.Id = up.Iduser where IsOperator = 1 order by NEWID() end else begin select @Id Id end
if (@idtask = 'B77E5601-A103-4A41-B1FD-6E82EEB6B46A') begin declare @state int select @ID = idoperator from clients where id = @idabonent SELECT top 1 @state = h.state FROM A_Users u LEFT JOIN (SELECT h.* FROM ( SELECT UserId, max(TimeChange) TimeChange FROM A_UserStateHistory GROUP BY UserId ) t JOIN A_UserStateHistory h ON t.UserId = h.UserId AND h.TimeChange = t.TimeChange ) h ON h.UserId = u.Id WHERE u.id = @ID if (@state= 0 or @state is null) begin select u.Id from A_Users u inner join A_UserParams up on u.Id = up.Iduser where IsOperator = 1 order by NEWID() end else begin select @ID Id end end