
CREATE FUNCTION [dbo].[ApiKonfiguratorExtInfo]
(
	@PozId int

)
RETURNS nvarchar(MAX)
AS
BEGIN

declare @Info nvarchar(MAX)
set @Info = ''
select @Info+=d.Name +':'+case when( d.ValueType ='Towar') then ( select Kod from dbo.Towary t where t.ID = e.ValueId) else   e.Value end +'|' 
from dbo.TwrKonfigElems e
JOIN dbo.DefsTwrKonfig d ON e.Definicja = d.ID
where
(ISNULL(Value,'')<>'' OR ValueId<>0) 
and Pozycja = @PozId


return @Info;

END
