Can You Pass Expressions to Stored Procedure Parameters?
Submitted by: AdministratorCan you pass expressions to stored procedure parameters? The answer is no.
When executing stored procedures, all input values must be entered as data literals, which can be specified within single quotes ('), or without them if they cause no confusion. The tutorial exercise below shows you how input values should be specified:
CREATE PROCEDURE area_of_circle @radius REAL
AS BEGIN
PRINT 'Radius = ' + STR(@radius,9,3);
PRINT 'Area = ' + STR(3.14*@radius*@radius,9,3);
END;
GO
-- Input value without quotes
EXEC area_of_circle 1.5;
GO
Radius = 1.500
Area = 7.065
-- Input value with quotes
EXEC area_of_circle '1.5';
GO
Radius = 1.500
Area = 7.065
-- Expressions are not allowed
EXEC area_of_circle 1.0+0.5;
GO
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '+'.
Submitted by: Administrator
When executing stored procedures, all input values must be entered as data literals, which can be specified within single quotes ('), or without them if they cause no confusion. The tutorial exercise below shows you how input values should be specified:
CREATE PROCEDURE area_of_circle @radius REAL
AS BEGIN
PRINT 'Radius = ' + STR(@radius,9,3);
PRINT 'Area = ' + STR(3.14*@radius*@radius,9,3);
END;
GO
-- Input value without quotes
EXEC area_of_circle 1.5;
GO
Radius = 1.500
Area = 7.065
-- Input value with quotes
EXEC area_of_circle '1.5';
GO
Radius = 1.500
Area = 7.065
-- Expressions are not allowed
EXEC area_of_circle 1.0+0.5;
GO
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '+'.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | How To Select Some Specific Rows from a Table in MS SQL Server? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | Does Index Slows Down INSERT Statements? |
☺ | What To Perform Pattern Match with the LIKE Operator? |
☺ | How To Execute the Cursor Queries with "OPEN" Statements? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Sybase Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |