test
Sql
code posted
by
mlp
created at 01 Aug 19:11
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
select u.u_logon_name as UserName, ty.TaxYear as TaxYear, sum(el.item_qty) as Miles from dbo.INS_EXPENSE_LINES el join dbo.INS_EXPENSE_HEADER eh on el.expense_ref = eh.expense_ref join dbo.INS_USERS u on eh.user_id = u.u_logon_name join ( select line_id, case when item_date < cast(cast(year(item_date) as varchar)+'-05-06' as datetime) then year(item_date)-1 else year(item_date) end as TaxYear from dbo.INS_EXPENSE_LINES el join dbo.INS_EXPENSE_TYPES et on el.expense_type = et.g_id where et.s_IsMileageCode = 'Y' and et.s_IsPrivateMileage = 'N') ty on el.line_id = ty.line_id where eh.status_id = '34' group by u.u_logon_name, ty.TaxYear |
818 Bytes in 2 ms with coderay