CREATE FUNCTION [_SMDBA_].[GET_PR_LINE_ITEMS_HTML] ( @PRNo int ) RETURNS nvarchar(4000) AS BEGIN -- Declare the return variable here DECLARE @LineItems nvarchar(4000) SET @LineItems = '' + 'Description' + '' + 'Unit Price' + '' + 'Qty Ord' + '' + 'Amount' + '' DECLARE @Description nvarchar(50), @UnitPrice float, @QtyOrd smallint, @Amount float -- Add the T-SQL statements to compute the return value here DECLARE cur CURSOR FOR SELECT [Description], [Unit Price], [Qty Ord], [Amount] FROM _SMDBA_.[Purchasing Items] WHERE [ReqN] = @PRNo AND [InActive:] = 0 OPEN cur FETCH NEXT FROM cur INTO @Description, @UnitPrice, @QtyOrd, @Amount WHILE (@@fetch_status <> -1) BEGIN IF (@@fetch_status <> -2) BEGIN SELECT @LineItems = @LineItems + '' + @Description + '' + '$' + CONVERT(nvarchar(10), @UnitPrice) + '' + CAST(@QtyOrd As nvarchar(4)) + '' + '$' + CONVERT(nvarchar(10),@Amount) + '' END FETCH NEXT FROM cur INTO @Description, @UnitPrice, @QtyOrd, @Amount END CLOSE cur DEALLOCATE cur -- Return the result of the function RETURN @LineItems END