ALTER VIEW [dbo].[VWPMO_WD_DOC_SEARCH] AS 
SELECT 
	T.dwDocID as DocID
	,[dbo].[FNPMO_GET_WINDREAM_VKT_INT](T.dwDocID,20006)							AS [ENTITY_ID]
	,[dbo].[FNPMO_GET_WINDREAM_VKT_INT](T.dwDocID,20005)							AS [RECORD_ID]
	,T.dwInteger24																	AS [PARENT_ID]
	,dbo.FNPMO_GET_WINDREAM_FILE_PATH (T.dwDocID) + T.szLongName					AS FULL_FILENAME
	,szLongName																		as [Filename], 
	T.szText39																		AS Doctype
	,T.dwVersionNumber																AS [Version]
	,CAST(CAST(CONVERT(DATE,CONVERT(VARCHAR(10),T.dwCreationDate)) AS DATETIME) + CAST(STUFF(STUFF(REPLICATE('0',6-LEN(T.dwCreation_Time)) + convert(VARCHAR(6),T.dwCreation_Time),3,0,':'),6,0,':') AS DATETIME) AS DATETIME) AS Creation_DateTime
	,T1.szDocTypeName																AS OBJECTTYPE
FROM 
	[172.24.12.41\BRAINPOOL].windream60.dbo.BaseAttributes T
	,[172.24.12.41\BRAINPOOL].windream60.dbo.ObjectType T1
WHERE 
	T.dwObjectTypeID = T1.dwObjectTypeID 
	AND T.dwInteger23 is not null 

GO

USE [DD_ECM]
GO
ALTER FUNCTION [dbo].[FNPMO_GET_WINDREAM_VKT_INT](@pdwDocID INTEGER,@pdwAttributID INTEGER)
RETURNS VARCHAR(4000)
AS 
BEGIN
	DECLARE	
		@RESULT		VARCHAR(4000),
		@VALUE	INTEGER
		

		
	DECLARE	c_RESULT CURSOR FOR SELECT [dwValue] FROM [172.24.12.41\BRAINPOOL].windream60.[dbo].[Vector] 
	where dwDocID = @pdwDocID and dwAttrID = @pdwAttributID


	BEGIN
		OPEN c_RESULT 
		FETCH NEXT FROM c_RESULT INTO @VALUE
    
		WHILE @@FETCH_STATUS = 0
			BEGIN
				IF LEN(@RESULT) > 0
					SET @RESULT = @RESULT + '#' + CONVERT(VARCHAR(30),@VALUE)
				ELSE
					SET @RESULT = '#' + CONVERT(VARCHAR(30),@VALUE) 
				FETCH NEXT FROM c_RESULT INTO @VALUE
			END

		CLOSE c_RESULT
		DEALLOCATE c_RESULT

		RETURN(@RESULT)
	END
END




