Monday, 15 April 2013

Create Multiplication Table in SQL SERVER


Creating Multiplication Table in SQL SERVER


I have attended an interview 2 days ago; In that interview I got a question in which I have to create a Multiplication Table for a particular Number in PL/SQL... So Here I am with a Multiplication table of 8..
You can Modify the same for other integers..



DECLARE @i INT 
SET @i = 0;
 
-- Alternate syntax to club above two lines
DECLARE @j INT 
SET @j= 8; -- Multiplicaiton table for 8. Change this.
 
PRINT 'Multipliction table for ' 
    + CONVERT(VARCHAR, @j) + ':' + CHAR(13); -- newline
 
 
WHILE (@i < 10) -- show 1 to 10
BEGIN
 SET @i = @i + 1; -- Can be written as SET @i += 1; 
 PRINT CONVERT(VARCHAR, @i) + ' x 8 = ' + CONVERT(VARCHAR, @i*@j);
END

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top