cast(iif(datepart(dd,getdate()) < datepart(dd,iif(teintritt is null,eintritt1,teintritt)), ( datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) - 1 ) / 12, datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) / 12) as varchar(5)) + iif(iif(datepart(dd,getdate()) < datepart(dd,iif(teintritt is null,eintritt1,teintritt)), ( datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) - 1 ) / 12, datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) / 12) = 1, ' Jahr ', ' Jahre ') +
cast(iif(iif(datepart(dd,getdate()) < datepart(dd,iif(teintritt is null,eintritt1,teintritt)), datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) - 1 - datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) / 12 * 12, datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) - datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) / 12 * 12) = -1,11,iif(datepart(dd,getdate()) < datepart(dd,iif(teintritt is null,eintritt1,teintritt)), datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) - 1 - datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) / 12 * 12, datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) - datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) / 12 * 12)) as varchar(5)) + iif(iif(datepart(dd,getdate()) < datepart(dd,iif(teintritt is null,eintritt1,teintritt)), datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) - 1 - datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) / 12 * 12, datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) - datediff(mm,iif(teintritt is null,eintritt1,teintritt),getdate()) / 12 * 12) = 1, ' Monat ', ' Monate ') +
cast(iif(datepart(dd,getdate()) > datepart(dd,iif(teintritt is null,eintritt1,teintritt)), datepart(dd,getdate()) - datepart(dd,iif(teintritt is null,eintritt1,teintritt)) + 1, day(dateadd(mm,datediff(mm,-1,iif(teintritt is null,eintritt1,teintritt)),-1)) - datepart(dd,iif(teintritt is null,eintritt1,teintritt)) + datepart(dd,getdate())) as varchar(5)) + iif(iif(datepart(dd,getdate()) > datepart(dd,iif(teintritt is null,eintritt1,teintritt)), datepart(dd,getdate()) - datepart(dd,iif(teintritt is null,eintritt1,teintritt)) + 1, day(dateadd(mm,datediff(mm,-1,iif(teintritt is null,eintritt1,teintritt)),-1)) - datepart(dd,iif(teintritt is null,eintritt1,teintritt)) + datepart(dd,getdate())) = 1, ' Tag ', ' Tage ') as Betriebszugeh