SQL Server scalar value function instance and cannot invoke reason analysis

Source: Internet
Author: User
Tags scalar

SQL Server scalar value function instance and cannot invoke cause analysis
--scalar value function

Set ANSI_NULLS on
Go
SET QUOTED_IDENTIFIER on
Go
-================================ =============
--Author: <author,,name>
--Create Date: <create date,,>
--Description: <de Scription,,>
--=============================================
Create function <scalar_function_name, sysname, functionname>
(
--Add the parameters for the function here
< @param1, sysname, @p1 > <d ATA_TYPE_FOR_PARAM1,, int>
)
returns <function_data_type,,int>
as
begin
--Declare the Return variable
Declare < @resultvar, sysname, @result > <function_data_type, Int>

--Add t He T-SQL statements to compute "return value" here
Select < @resultvar, sysname, @result > = < @param1, Sysna Me, @p1

--Return the result's function
return < @resultvar, sysname, @result

end


With the MS SQL scalar value function, you should precede the function with "dbo.", otherwise the "not recognized built-in function name" error will be reported. For example

declare @whichdb tinyint;
Select @whichdb = user_getwhichdb (1);--to see which database tutorial

=================================================

--Scalar value function

alter function [dbo]. [USER_GETWHICHDB]
(
@userid int = 0
)
Returns tinyint
With EXECUTE AS caller
As
Begin
declare @whichdb tinyint;
Set @whichdb = 1;
If @userid >= 115098
Set @whichdb = 2;

return (@whichdb);
End

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.