Collections:
Passing Expressions to Function Parameters in SQL Server
Can You Pass Expressions to Function Parameters in SQL Server Transact-SQL?
✍: FYIcenter.com
Can you pass expressions to stored procedure parameters? The answer is yes.
When executing functions, input values can be written as expressions. But the resulting value data type must match the parameter. The tutorial exercise below shows you how input values should be specified:
USE FyiCenterData; GO CREATE FUNCTION Area(@radius REAL) RETURNS REAL AS BEGIN RETURN 3.14*@radius*@radius; END; GO -- Input value data matches the parameter PRINT 'Area of a circle: '+STR(dbo.Area(1.5),9,3); GO Area of a circle: 7.065 -- Input value data does not match the parameter PRINT 'Area of a circle: '+STR(dbo.Area('1.5'),9,3); GO Msg 102, Level 15, State 1, Line 3 Incorrect syntax near 'Area'. -- Expressions are allowed PRINT 'Area of a circle: '+STR(dbo.Area(1.0+0.5),9,3); GO Area of a circle: 7.065
2016-12-18, 758👍, 0💬
Popular Posts:
How To List All Login Names on the Server in SQL Server? If you want to see a list of all login name...
What are binary literals supported in SQL Server Transact-SQL? Binary literals in Transact-SQL are s...
How to execute statements under given conditions in SQL Server Transact-SQL? How to use IF ... ELSE ...
What are DDL (Data Definition Language) statements for tables in SQL Server? DDL (Data Definition La...
How To Get Year, Month and Day Out of DATETIME Values in SQL Server Transact-SQL? You can use DATEPA...