I want to create a stored procedure with a table-valued function as a column. I want to use one of the other column values as the parameter for the function.
ALTER PROCEDURE [dbo].[AuditReportLeaseID]
@leaseID int
AS
BEGIN
SET NOCOUNT ON;
SELECT
a.assetID as Asset, a.Location,
CONVERT(VARCHAR, a.auditdate, 101) AS Date,
a.qtyaudit AS Qty,
c.classname AS Class, a.grade AS Grade,
a.serialnumber AS [S/N],
a.materialdescription AS Description, a.Notes,
(SELECT tf.AD
FROM fGetAuditDescrConcat(a.assetId) tf) AS AuditDescription
FROM
audit a
LEFT OUTER JOIN
ORDER_DETAILS od ON a.assetID = od.assetId
INNER JOIN
class c ON a.classid = c.classid
WHERE
a.classID = c.classID
AND a.leaseID = @leaseID
ORDER BY
class, grade, a.materialDescription
END
This procedure will return multiple rows and I want to use the value of the first column a.assetID
(which is a varchar(64)
) as the parameter to the fGetAuditDescrConcat
function.
Is this possible?