
CREATE FUNCTION [dbo].[ApiRoofProdStatus]
(
	@OrderId int
)
RETURNS nvarchar(MAX)
AS
BEGIN

declare @Pozycje nvarchar(MAX)
set @Pozycje = ''

select   @Pozycje+= st.NumberString
--+'['+ case when(st.Status=0) then 'bufor' else 'zatwierdzone' end +']|' 
from dbo.ApiRoofSettelments st
JOIN dbo.ApiObjectRelations obr 
ON obr.RelObjectId = st.Id and obr.RelObjectType=600 
and obr.ObjectType=10 and obr.ObjectId = @OrderId
and st.Status<2

return  @Pozycje;

END



