I came up with this for my view - I hope this is correct....
CREATE VIEW [dbo].[CT_Documents]
dbo.acFindAnyVariableValueBOM(N'Description', DocumentID, LatestRevisionNo) AS Description
FROM dbo.Documents AS d
That will work. Another approach if you don't want to go the view route is to do something like the following as an example...
SELECT top 10 D.DocumentID, D.Filename,
(SELECT dbo.acFindAnyVariableValueBOM(N'Description',D.DocumentID, D.LatestRevisionNo) AS Description) AS Description
From Documents AS D
I'm not terribly familiar with this SP, but if all you need is a variable value this is the method I typically use
with maxvars as (select documentid, MAX(RevisionNo) RevisionNo, configurationid, variableid from VariableValue group by DocumentID, ConfigurationID, VariableID) select* from Documents d inner join VariableValue vv on vv.DocumentID = d.DocumentID inner join maxvars mv on mv.DocumentID = vv.DocumentID and mv.ConfigurationID = vv.ConfigurationID and mv.RevisionNo = vv.RevisionNo and mv.VariableID = vv.VariableID
Also take a look at dbo.fnHexNumber, it will save you some typing on your converts to hex.
select dbo.fnHexNumber(documentid, 8, 1) from Documents