• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 122
  • Last Modified:

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

0
r3nder
Asked:
r3nder
1 Solution
 
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
 
r3nderAuthor Commented:
Thanks pcelba
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now