Monday, August 7, 2023

.::: MSSQL: Create Store Procedure Simple Calculator :::.



1. Create store procedure Sp_Simple_Calculator

CREATE PROCEDURE Sp_Simple_Calculator
    @Num1 decimal,
    @Num2 decimal
AS
BEGIN
    SELECT @@ServerName as ServerName,db_name() as [DBName],getdate() [Date],'Result @Num1 & @Num2' as Desctiption,@Num1 as [Num1],@Num2 as [Num2], @Num1 + @Num2 AS 'Result Additional',
    @Num1 - @Num2 AS 'Result Substraction',@Num1 * @Num2 AS 'Result Multiplication',@Num1 / @Num2 AS 'Result Division';
END
 


2. test execute ( example Numb 1=100, Numb 2=20 
 
exec Sp_Simple_Calculator '100','20';
exec Sp_Simple_Calculator '200','40';
exec Sp_Simple_Calculator '100','400';


3. check result
 


4. drop Store procedure if want delete
drop procedure Sp_Simple_Calculator

No comments:

Post a Comment

Popular Posts