Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to rewrite the code of MSSQL server Stored Procedure to Mysql stored procedure..

below is my stored procedure for login in mssql..
SQL
create procedure sp_login(@uid int out,@uname varchar(30),@pwd varchar(30) 
as
    if exists(select * from reg where uname=@uname and pwd=@pwd)
        begin
            select  @uid=uid from reg where uname=@uname and pwd=@pwd
            return 0
        end
    else
        begin
            return 1
        end
Posted
Updated 5-Jun-13 20:39pm
v3

1 solution

Hello,

Following code shows the MySQL version of your stored procedure. Stored procedures don't return a value as opposed to stored functions.
SQL
DROP PROCEDURE IF EXISTS sp_login;
CREATE FUNCTION sp_login (OUT po_uid INT, pi_uname VARCHAR(30), pi_pwd VARCHAR(30))
BEGIN
    SELECT uid INTO po_uid 
    FROM reg 
    WHERE uname = pi_uname AND pwd = pi_pwd;
END;

Regards,
 
Share this answer
 
Comments
abey e mathews 6-Jun-13 4:08am    
is this

DELIMITER $$

CREATE PROCEDURE `database_name`.`sp_login` (OUT po_uid INT, pi_uname VARCHAR(30), pi_pwd VARCHAR(30))
BEGIN
SELECT uid INTO po_uid
FROM reg
WHERE uname = pi_uname AND pwd = pi_pwd;
END
abey e mathews 6-Jun-13 4:10am    
is any alternate way for "return 0"
Prasad Khandekar 6-Jun-13 6:49am    
You can change select as follows

SELECT COALESCE(uid, 0) INTO po_uid
FROM reg
WHERE uname = pi_uname AND pwd = pi_pwd;

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