Как я могу улучшить свою SQL-функцию, содержащую более 70 условных операторов, которые вычисляют графики сдвигов?
У меня есть функция, которая вычисляет и выводит графики сдвигов, в моей функции у меня есть 70+ условных операторов, но есть ошибка
String or binary data would be truncatedвот мой код:
GO ALTER function [dbo].[fn_ComputeShiftCode] ( @login time, @logout time ) returns varchar(10) as begin declare @shiftcode int set @shiftcode = (select case when @login <= '4:00:00' and @logout >= '13:00:00' then 1 when @login <='5:00:00' and @logout >= '14:00:00' then 2 when @login <='6:00:00' and @logout >= '15:00:00' then 3 when @login <='6:00:00' and @logout >= '17:00:00' then 4 when @login <='7:00:00' and @logout >= '14:00:00' then 5 when @login <='7:00:00' and @logout >= '16:00:00' then 6 when @login <='7:00:00' and @logout >= '16:00:00' then 7 when @login <='8:00:00' and @logout >='17:00:00' Then 8 when @login <='8:00:00' and @logout >='19:00:00' Then 9 when @login <='9:00:00' and @logout >='18:00:00'Then 10 when @login <='14:00:00' and @logout >='21:00:00'Then 11 when @login <='14:00:00' and @logout >='23:00:00'Then 12 when @login <='16:00:00' and @logout >='1:00:00' Then 13 when @login <='17:00:00' and @logout >='2:00:00' Then 14 when @login <='18:00:00' and @logout >='3:00:00' Then 15 when @login <='21:00:00' and @logout >='6:00:00' Then 16 when @login <='20:00:00' and @logout >='5:00:00' Then 17 when @login <='15:00:00' and @logout >='0:00:00' Then 18 when @login <='19:00:00' and @logout >='4:00:00' Then 19 when @login <='3:00:00' and @logout >='12:00:00'Then 20 when @login <='10:00:00' and @logout >='19:00:00'Then 23 when @login <='12:00:00' and @logout >='21:00:00'Then 24 when @login <='3:00:00' and @logout >='13:30:00'Then 25 when @login <='5:00:00' and @logout >='15:30:00'Then 26 when @login <='0:00:00' and @logout >='23:00:00'Then 28 when @login <='6:00:00' and @logout >='16:30:00'Then 32 when @login <='7:00:00' and @logout >='17:30:00'Then 33 when @login <='8:00:00' and @logout >='18:30:00'Then 34 when @login <='9:00:00' and @logout >='19:30:00'Then 35 when @login <='10:00:00' and @logout >='20:30:00'Then 36 when @login <='11:00:00' and @logout >='21:30:00'Then 37 when @login <='12:00:00' and @logout >='22:30:00'Then 38 when @login <='13:00:00' and @logout >='23:30:00'Then 39 when @login <='14:00:00' and @logout >='0:30:00' Then 40 when @login <='15:00:00' and @logout >='1:30:00' Then 41 when @login <='16:00:00' and @logout >='2:30:00' Then 42 when @login <='17:00:00' and @logout >='3:30:00' Then 43 when @login <='18:00:00' and @logout >='4:30:00' Then 44 when @login <='19:00:00' and @logout >='5:30:00' Then 45 when @login <='20:00:00' and @logout >='6:30:00' Then 46 when @login <='21:00:00' and @logout >='7:30:00' Then 47 when @login <='22:00:00' and @logout >='8:30:00' Then 48 when @login <='23:00:00' and @logout >='9:30:00' Then 49 when @login <='12:00:00' and @logout >='10:30:00'Then 50 when @login <='1:00:00' and @logout >='12:00:00'Then 51 when @login <='2:00:00' and @logout >='13:00:00'Then 52 when @login <='3:00:00' and @logout >='14:00:00'Then 53 when @login <='4:00:00' and @logout >='15:00:00'Then 54 when @login <='5:00:00' and @logout >='16:00:00'Then 55 when @login <='6:00:00' and @logout >='17:00:00'Then 56 when @login <='7:00:00' and @logout >='18:00:00'Then 57 when @login <='8:00:00' and @logout >='19:00:00'Then 58 when @login <='9:00:00' and @logout >='20:00:00'Then 59 when @login <='10:00:00' and @logout >='21:00:00'Then 60 when @login <='11:00:00' and @logout >='22:00:00'Then 61 when @login <='0:00:00' and @logout >='11:00:00'Then 62 when @login <='13:00:00' and @logout >='0:00:00' Then 63 when @login <='14:00:00' and @logout >='1:00:00' Then 64 when @login <='15:00:00' and @logout >='2:00:00' Then 65 when @login <='16:00:00' and @logout >='3:00:00' Then 66 when @login <='17:00:00' and @logout >='4:00:00' Then 67 when @login <='18:00:00' and @logout >='5:00:00' Then 68 when @login <='19:00:00' and @logout >='6:00:00' Then 69 when @login <='20:00:00' and @logout >='7:00:00' Then 70 when @login <='21:00:00' and @logout >='8:00:00' Then 71 when @login <='22:00:00' and @logout >='9:00:00' Then 72 when @login <='23:00:00' and @logout >='10:00:00'Then 73 when @login <='13:00:00' and @logout >='22:00:00'Then 21 when @login <='1:00:00' and @logout >='10:00:00'Then 22 when @login <='22:00:00' and @logout >='7:00:00' Then 75 when @login <='11:00:00' and @logout >='20:00:00'Then 76 when @login <='2:00:00' and @logout >='11:00:00'Then 77 when @login <='0:00:00' and @logout >='9:00:00' Then 78 when @login <='16:00:00' and @logout >='23:00:00'Then 79 when @login <='7:00:00' and @logout >='14:00:00'Then 80 when @login <='14:00:00' and @logout >='21:00:00'Then 81 when @login <='21:00:00' and @logout >='4:00:00' Then 82 when @login <='22:00:00' and @logout >='5:00:00' Then 83 when @login <='17:00:00' and @logout >='0:00:00' Then 84 when @login <='8:00:00' and @logout >='18:30:00'Then 85 when @login <='8:00:00' and @logout >='18:00:00'Then 86 when @login <='4:00:00' and @logout >='14:30:00'Then 27 when @login <='1:00:00' and @logout >='11:30:00'Then 29 when @login <='2:00:00' and @logout >='12:30:00'Then 30 when @login <='5:00:00' and @logout >='15:30:00'Then 31 when @login <='12:00:00' and @logout >='23:00:00'Then 74 end ) return @shiftcode end
Что я уже пробовал:
Я использовал эту функцию из хранимой процедуры, которая выводит оператор Select, а затем вставляет его в производную таблицу