create stored proc in sql from mysql

I have a mysql stored procedure I want to turn into a sql stored procedure
how would it be done?
CREATE PROCEDURE fill_calendar(mystart_date DATE, end_date DATE)
BEGIN
  DECLARE crt_date DATE;
  DECLARE Yr INT;
  DECLARE Mo INT;
  SET crt_date = start_date;
  SET Yr= Year(mystart_date);
  SET Mo= Month(mystart_date);
  
  WHILE crt_date < end_date DO
  
    INSERT INTO calendar(Yr,Mo) VALUES(Yr,Mo);
    
    SET crt_date = DATE_ADD(crt_date, INTERVAL 1 MONTH);
    SET Yr= Year(crt_date);
  SET Mo= Month(crt_date);
  END WHILE;

Open in new window

LVL 6
r3nderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pcelbaCommented:
The T-SQL syntax is just slightly different:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE dbo.fill_calendar
@mystart_date DATE, 
@end_date DATE

AS
BEGIN
  
  DECLARE @crt_date DATE;
  DECLARE @Yr INT;
  DECLARE @Mo INT;
  SET @crt_date = @mystart_date;
  SET @Yr = Year(@mystart_date);
  SET @Mo = Month(@mystart_date);
  
  WHILE @crt_date < @end_date
  BEGIN
    INSERT INTO calendar (Yr,Mo) VALUES(@Yr,@Mo);
    
    SET @crt_date = DATEADD(month, 1, @crt_date);
    SET @Yr = Year(@crt_date);
    SET @Mo = Month(@crt_date);
  END 

END

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
r3nderAuthor Commented:
Thanks pcelba
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.