Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
hi,i want to create this funcion but sql not allowed,
SQL
create FUNCTION returnrahgiri(@rahgiri text)
RETURNS text
as
BEGIN
return (Select response  from work_with_us  where (response=@rahgiri))
END

message error:
Msg 2716, Level 16, State 1, Procedure returnrahgiri, Line 1
Column, parameter, or variable #0: Cannot specify a column width on data type text.

how i can fix this problem???
Posted
Updated 22-Sep-13 1:10am
v2
Comments
Mike Meinz 22-Sep-13 7:16am    
Your Select statement is returning the value used in the Where clause. You already know the value of Response, why do you need to execute a function to retrieve the value of Response?

The Data Type Text is deprecated. You should not use it in new development. Use varchar or nvarchar instead.

How are you calling this function from your application?

On SQL Server 2012, I get this error message when trying to create the function:
Msg 2733, Level 16, State 1, Procedure returnrahgiri, Line 6
The text data type is invalid for return values.
phil.o 23-Sep-13 1:55am    
I agree ; totally nonsense to create a stored procedure to return a value that you already know in the first place. Maybe it's a typo, the OP might want to retrieve the 'response' from an ID field but has not done the right query. Without more information it's hard to tell.

1 solution

With Functions in SQL, you can't use Text, try using VARCHAR(MAX) which works the same way as Text
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900