Click here to Skip to main content
16,004,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this Store Procedure in MS-SQL:

SQL
USE [LoginDB]
GO
/****** Object:  StoredProcedure [dbo].[Validate_User]    Script Date: 08/24/2014 15:29:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER  PROCEDURE [dbo].[Validate_User]
	@Username NVARCHAR(20),
	@Password NVARCHAR(20)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @UserId INT, @LastLoginDate DATETIME
	
	SELECT @UserId = UserId, @LastLoginDate = LastLoginDate 
	FROM Users WHERE Username = @Username AND [Password] = @Password
	
	IF @UserId IS NOT NULL
	BEGIN
		IF NOT EXISTS(SELECT UserId FROM UserActivation WHERE UserId = @UserId)
		BEGIN
			UPDATE Users
			SET LastLoginDate =  GETDATE()
			WHERE UserId = @UserId
			SELECT @UserId [UserId] -- User Valid
		END
		ELSE
		BEGIN
			SELECT -2 -- User not activated.
		END
	END
	ELSE
	BEGIN
		SELECT -1 -- User invalid.
	END
END


-------------------
How should i write this store procedure in MySQL ?
Posted
Updated 24-Aug-14 4:05am
v2
Comments
[no name] 24-Aug-14 8:45am    
You would take out the MS specific functionality and use the equivalent MySQL functionality.
Abhishek Pant 24-Aug-14 10:19am    

Hey, try this
Convert MS-SQL Server stored procedure to MySQL Query
^]

http://stackoverflow.com/questions/20329643/convert-ms-sql-server-stored-procedure-to-mysql-query

:) :)
 
Share this answer
 
v5
There are no tools for this, so you have to do the conversion manually.
This is a pretty straight forward conversion, but normally I would start with documenting the functionality of the SP. It is good for the understanding to have your procedures documented.

Then check out the MySQL site and read the documentation for their stored procedures.
The DDL syntax is similar and the SQL syntax is the same.

Chapter 19 Stored Programs and Views[^]

13.1.12 CREATE PROCEDURE and CREATE FUNCTION Syntax[^]

MySQL Stored Procedure[^]
 
Share this answer
 
Check this post.It illustrated all major differences between structures of stored procedures in Microsoft SQL and MySQL. Go through it and convert your MS SQL Stored Procedures to MySQL
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900