CREATE OR ALTER VIEW VWIDB_DOC_STATES AS 
SELECT 
	A.GUID ID
	,A.MY_OBJECT_ID AS IDB_OBJ_ID
	,C.LANG_ID
	,LANG.LANG_CODE
	,TERM.TERM_VALUE AS STATE_LANG 
	,A.ADDED_WHEN
FROM
	TBIDB_MYOBJECT_STATES A INNER JOIN TBIDB_OBJ_STATES B ON A.STATE_ID = B.GUID 
	INNER JOIN TBIDB_LANGUAGE_TERM C ON B.GUID = C.OBJECT_ID
	INNER JOIN TBIDB_LANGUAGE LANG ON C.LANG_ID = LANG.GUID
	INNER JOIN TBIDB_TERM_VALUE_VARCHAR TERM ON C.TERM_ID = TERM.GUID
WHERE 
	C.KIND_TYPE = 3
GO