

	CREATE VIEW [dbo].[ApiHolidaysLimitView] as

		select lim.*, PRA_Kod WorkerCode from (
		select 
		p1.PLN_PlnId Id , p1.PLN_PraId WorkerId, p1.PLN_Rok Year, 
		p1.PLN_PrzeniesienieF FromPreviousYear, p1.PLN_NalezneLacznieF Total, p1.PLN_WykorzystaneF Used, p1.PLN_PozostaloF  Remaining
		from CDN.PracLimit p1 where PLN_PlnId= ( select top 1 PLN_PlnId from CDN.PracLimit p2 where p2.PLN_PraId = p1.PLN_PraId and p2.PLN_Rok = p1.PLN_Rok ORDER BY p2.PLN_WaznyOd DESC))
		lim JOIN CDN.PracKod ON WorkerId = PRA_PraId 
GO


