Spending sometime for
T-SQL on weekends made me write a stored procedure that returns
Multiplication Table for any given number.
Stored Procedure Code:
CREATE PROCEDURE dbo.usp_MultiplicationTable
@N INT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @I INT = @N, @J INT = 1
DECLARE @TV TABLE (RESULT VARCHAR(20))
WHILE (@J <= 10)
BEGIN
INSERT INTO @TV
SELECT CAST(@I AS VARCHAR) + CHAR(32) + '*' + CHAR(32) +
CAST(@J AS VARCHAR) + CHAR(32) + '=' + CHAR(32) + CAST(@I * @J AS VARCHAR)
SET @J = @J + 1
END
SELECT * FROM @TV;
END
Execution Code:
On
passing '2' as the input value to the stored procedure, it returned below
output:
Hope this helps someone!
Conclusion: T-SQL is like a girl friend. You get close to it, it loves back. You go away, it starts hating you. So Happy TSQLing ;)
No comments:
Post a Comment