-- #New: 13.12.17/J.Fes
-- #Doc: returns for DS all DS Version having a releation to folder or ohter Objects
-- #Doc: if no Data is returend then DS and DS Versions has no releations to any PWORKSPACEOBJECT
SELECT
  pd.puid AS DSPuid,
  pdVer.puid AS DSVerPuid,
  -- #Doc: 1* colume3: Returns Name of Dataset Version
  -- ,wsopdVer.pobject_name + ',' + CONVERT(varchar(64), (ra.phighest_rev-rev.pseq+1)) as DSNameAndVersion
  wso.pobject_name as DSVerHasRefTo_ObjectName
 FROM
  infodba.PDATASET pd
  INNER JOIN infodba.PREVISIONS rev ON (rev.puid = pd.rrev_chain_anchoru)
  INNER JOIN infodba.PREVISIONANCHOR ra ON (ra.puid = pd.rrev_chain_anchoru)
  INNER JOIN infodba.PREF_LIST_0 pdVer ON (pdVer.puid = rev.pvalu_0) AND (pdVer.pseq = 0)
  --  LEFT  JOIN infodba.PREF_NAMES_0 rn ON (rn.puid = pdVer.puid) AND (pdVer.pseq = rn.pseq)

  INNER JOIN infodba.PCONTENTS c ON (c.pvalu_0 = pdVer.puid)
  INNER JOIN infodba.PWORKSPACEOBJECT wso ON (wso.puid = c.puid)
  -- #Doc: 1* JOIN Needet for colume3
  -- INNER JOIN infodba.PWORKSPACEOBJECT wsopdVer ON (wsopdVer.puid = pdVer.puid)
WHERE
  pd.puid = :ds_puid
