Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UDF Question
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
UDF Question
Miscellaneous
Thread ID:
00713031
Message ID:
00713031
Views:
44
Can I create a udf function that performs a query, that returns a single row with a single field, and then return the value of the single column/record?

Here is what I have tried:
CREATE FUNCTION CaseResourceCost  (@meetID int)  
RETURNS decimal(12,2) AS  
BEGIN 
        Declare @returnValue decimal(12,2)
        select isnull(sum(cocasedata.itemunitcost * coCaseData.ActualQty),0) as avgResCost
	FROM dbo.meetings  INNER JOIN  
	             dbo.meetproc  ON meetings.meetingnumber =meetproc.meetingnumber INNER JOIN 
	             dbo.cocasedata ON meetings.meetingnumber = dbo.cocasedata.meetingnumber 
	             where meetings.meetingnumber = @MeetID

      set @returnValue= avgResCost
      return (@returnValue)
END
But I get the following error
---------------------------
Microsoft SQL-DMO (ODBC SQLState: 42S22)
---------------------------
Error 207: Invalid column name 'avgResCost'.
Select statements included within a function cannot return data to a client.
---------------------------
OK
---------------------------
Next
Reply
Map
View

Click here to load this message in the networking platform