IF OBJECT_ID('dbo.fnGetDokumentumIntezmenyCime') IS NOT NULL BEGIN
  DROP FUNCTION dbo.fnGetDokumentumIntezmenyCime
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION dbo.fnGetDokumentumIntezmenyCime (@tanevId INT)
RETURNS NVARCHAR(MAX)
BEGIN  
  DECLARE @value NVARCHAR(MAX)

  SELECT
    @value = C_IRANYITOSZAM + ' ' + C_VAROS  + ISNULL( ', ' + C_KOZTERULETNEV + ' ', '') +  ISNULL(C_KOZTERULETJELLEGENEV + ' ','') + ISNULL(C_HAZSZAM, '')  + ISNULL(', ' + C_EMELET + '. emelet', '') + ISNULL(', ' + C_AJTO + '. ajtó', '')
  FROM T_INTEZMENYADATOK_OSSZES
  WHERE 
    C_TANEVID = @tanevId  
    AND TOROLT = 'F'

  RETURN @value  

END;