Добро пожаловать в форум, Guest >> Войти | Регистрация | Поиск | Правила | | В избранное | Подписаться | ||
Все форумы / Microsoft SQL Server |
![]() ![]() |
Рихтовщик Member Откуда: Москва Сообщений: 16 |
Есть таблица:CREATE TABLE BusinessCase( ID uniqueidentifier, CountItem int, OneTime int, Periodic int, WorkID uniqueidentifier, BudgetID uniqueidentifier) к ней есть запрос: select 'Итого расход' as Name, cast(sum( case CostItemID when '6F274CE0-4048-4A35-AD3E-028B56EA4D79' then case HatBusinessCase.TypeProject when 1 then case when BusinessCase.CountItem > 1000 then isnull(BusinessCase.OneTime,0)*1.5*BusinessCase.CountItem when BusinessCase.CountItem <= 1000 then isnull(BusinessCase.OneTime,0)*1.5*1000 when BusinessCase.CountItem <= 0 then 0 end else case when BusinessCase.CountItem > 1000 then isnull(BusinessCase.OneTime,0)*BusinessCase.CountItem when BusinessCase.CountItem <= 1000 then isnull(BusinessCase.OneTime,0)*1000 when BusinessCase.CountItem <= 0 then 0 end end when '664DF384-ED0E-4DB1-AD79-14F523A42C0F' then case HatBusinessCase.TypeProject when 1 then case when BusinessCase.CountItem > 1000 then isnull(BusinessCase.OneTime,0)*1.5*BusinessCase.CountItem when BusinessCase.CountItem <= 1000 then isnull(BusinessCase.OneTime,0)*1.5*1000 when BusinessCase.CountItem <= 0 then 0 end else case when BusinessCase.CountItem > 1000 then isnull(BusinessCase.OneTime,0)*BusinessCase.CountItem when BusinessCase.CountItem <= 1000 then isnull(BusinessCase.OneTime,0)*1000 when BusinessCase.CountItem <= 0 then 0 end end when 'E7E07D9E-C970-4CE1-BDD6-1A33124667C1' then case when BusinessCase.CountItem > 0 then 500000 end else isnull(BusinessCase.OneTime,0)*BusinessCase.CountItem end ) as varchar(10)) as OneTime, cast(SUM(isnull(BusinessCase.Periodic * BusinessCase.CountItem, 0)) as varchar(10)) as Periodic, 2 as Result from BusinessCase LEFT OUTER JOIN HatBusinessCase AS HatBusinessCase ON HatBusinessCase.WorkID = BusinessCase.WorkID where BusinessCase.WorkID = '2BCD4225-FAB8-4F4D-A598-27D386661067' and BusinessCase.BudgetID = '5CC0B805-496B-49AC-9140-3980A757C725' union all select 'Text' as Name, 'Окупаемость - ', 'Рентабельность - ' + ' %.', 4 as Result если выполнить этот запрос, получаем результат:
Откуда появляется этот лишний ноль после точки? Если закомментировать условия
то результат выполнения запроса получается без этого нуля... |
|||||
10 июл 14, 08:38 [16284559] Ответить | Цитировать Сообщить модератору |
гость 18
Guest |
*1.5 |
10 июл 14, 08:42 [16284576] Ответить | Цитировать Сообщить модератору |
alexeyvg Member Откуда: Moscow Сообщений: 31822 |
then 500000 - это целый тип 1.5*1000 - это decimal и т.д. Тип case в итоге получается как старший тип из всех используемых, и комментируя части выражения, вы отсекаете часть используемых типов. Самое простое - оберните case снаружи CONVERT-ом с приведением к тому типу, который вам нужен. |
||||
10 июл 14, 08:42 [16284577] Ответить | Цитировать Сообщить модератору |
alexeyvg Member Откуда: Moscow Сообщений: 31822 |
Можно его заменить на * 3 / 2 |
||
10 июл 14, 08:43 [16284584] Ответить | Цитировать Сообщить модератору |
Рихтовщик Member Откуда: Москва Сообщений: 16 |
большое человеческое спасибо... |
||||
10 июл 14, 08:53 [16284614] Ответить | Цитировать Сообщить модератору |
Все форумы / Microsoft SQL Server | ![]() |