Question : SQL Server 2005 Table-Valued Function Problem

I have created the below function to get a full description for a field from a table in my database.  However, when using my function, I get an error message that says:

"Cannot find either collumn "dbo" or the user-defined function or aggregate "dbo.getCode", or the name is ambiguous."

I don't know a whole lot about these functions, so I may be doing something wrong, but below is what I am executing in my query:

SELECT     dbo.getCode(grade, 'grades') AS Code
FROM         dwellings


And this is my function:

USE [MyDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[getCode]
(      
@Code char(20),
@CodeType char(20)
)
RETURNS TABLE
AS
RETURN
(
SELECT tbl_element_desc FROM codes_table WHERE tbl_type_code = '@CodeType' AND tbl_element = '@Code'
)



Thanks in advance for the help!

Answer : SQL Server 2005 Table-Valued Function Problem

sorry, we need to add BEGIN ... END
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
USE [MyDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[getCode] 
(      
@Code char(20),
@CodeType char(20)
)
RETURNS VARCHAR(200)
AS
BEGIN
RETURN 
(
SELECT TOP 1 tbl_element_desc FROM codes_table WHERE tbl_type_code = @CodeType AND tbl_element = @Code
)
END
Open in New Window Select All
Random Solutions  
 
programming4us programming4us