MySQL Forums
Forum List  »  Stored Procedures

MSSQL Developer trying to learn MySQL
Posted by: RJ Regalado
Date: May 25, 2021 04:41AM

Hello masters,


I am an MSSQL developer and I want to learn MySQL. This is the sample code I usually do in my projects. I believe that if someone ported this script to MySQL, I can now start my development with ease because everything I need is there. Except for the cursors which I really hate to use :D

Thanks in advance

This is my sample MSSQL code

--------------------------------------------------

CREATE PROCEDURE pd_GetReferenceNo
@refNo NVARCHAR(10) OUTPUT
AS BEGIN
SET @refNo = 'LUCKY777'
END


---------------------------------------------------


ALTER PROCEDURE pd_InsertDetails
@name NVARCHAR(MAX)
, @vaccineID BIGINT
AS BEGIN TRY
--DECLARE @name NVARCHAR(MAX) = 'Juan Dela Cruz'
-- , @vaccineID BIGINT = 4

DECLARE @refNo NVARCHAR(10)

IF (ISNULL(@name, '') = '') BEGIN
RAISERROR('sql|Please enter your name', 11, 1)
END

DECLARE @vacinesTbl TABLE ( ID BIGINT NOT NULL IDENTITY(1,1),
Brand NVARCHAR(50) NOT NULL)
INSERT @vacinesTbl (Brand)
VALUES ('Pfizer'), ('Moderna'), ('Sinovac'), ('Sputnik V'), ('Dengvaxia')


IF NOT EXISTS ( SELECT 1
FROM @vacinesTbl
WHERE ID = @vaccineID) BEGIN
RAISERROR('sql|Invalid Vaccine', 11, 1)
END

IF (( SELECT TOP 1
Brand
FROM @vacinesTbl
WHERE ID = @vaccineID) LIKE '%Dengvaxia%') BEGIN
RAISERROR('sql|That is not a covid-19 vaccine', 11, 1)
END

EXEC pd_GetReferenceNo @refNo OUTPUT

SELECT @refNo AS RefNo
, GETUTCDATE() As DateTimeEntry
END TRY
BEGIN CATCH
DECLARE @em NVARCHAR(MAX) = ERROR_MESSAGE()
, @es INT = ERROR_SEVERITY()
, @est INT = ERROR_STATE()
RAISERROR(@em, @es, @est)
END CATCH

Options: ReplyQuote


Subject
Views
Written By
Posted
MSSQL Developer trying to learn MySQL
1167
May 25, 2021 04:41AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.