Results 1 to 5 of 5

Thread: SQL Server to MySQL Stored Procedure

  1. #1
    Join Date
    Oct 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question SQL Server to MySQL Stored Procedure

    Hi,

    Although I am familiar with SQL, I am new to both SQL Server and MySQL and I have never worked with Stored Procedures or Functions before. I need help in converting the following Stored Procedure from SQL Server to MySQL 5.0 for one of the projects I'm working on (tried looking through MySQL manuals to no avail):

    CREATE PROCEDURE account_Login

    @ScreenName AS VARCHAR(50),
    @Password AS VARCHAR(50)

    AS

    SET NOCOUNT ON

    DECLARE @GoodLogin AS INTEGER

    SET @GoodLogin = (SELECT UserID
    FROM Users
    WHERE ScreenName = @ScreenName
    AND [Password] = @Password
    AND Status <> 0)

    IF @GoodLogin IS NOT NULL
    BEGIN
    UPDATE Users SET LastLogin = GETDATE() WHERE UserID = @GoodLogin
    END

    SELECT *
    FROM Users
    WHERE ScreenName = @ScreenName
    AND [Password] = @Password
    AND Status <> 0

    RETURN

    SET NOCOUNT OFF


    GO

    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS ON
    GO

    Any help will be greatly appreciated.

    Regards,

    Manny

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I have no working experience in MySQL but i've tried to convert your MS SQL Server stored procedure into a MYSQL stored procedure. Please checkout the following code

    Code:
    CREATE PROCEDURE account_Login (IN ScrName VARCHAR(50),IN Passwd AS VARCHAR(50) )
    BEGIN
    DECLARE GoodLogin INT
    SELECT UserID INTO GoodLogin FROM Users WHERE ScreenName = ScrName AND Password = Passwd AND Status <> 0;
    IF GoodLogin IS NOT NULL THEN
    	UPDATE Users SET LastLogin = CURDATE() WHERE UserID = GoodLogin;
    END IF;
    
    SELECT * FROM Users WHERE ScreenName = ScrName AND Password = Passwd AND Status <> 0;
    END
    Just to avoid the confusion i've used different names for the variables inside the procedure and the table columns.

  3. #3
    Join Date
    Oct 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you for your response. I've just tried the code sample you've provided (removed AS after Passwd on the first line) and I got an error on line 3. So I tried adding a semicolon at the end of the declare statement. It still gave me an error. I then removed the "INT" and the semicolon and the error moved to line 4 starting at "SELECT...."

    I compared the statement to the manual but everything seems fine. I'm not sure if I should just build the procedure into my application as it might be far easier (only problem is, I've got about 150 procedures that need adding) - I've been working with this procedure for over 48hrs now without doing anything else.

    Any other ideas welcome. Thanks again for your help.

    Manny

  4. #4
    Join Date
    Jan 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello Manny,
    Did you find a solution for this? I have some info and we can exchange if you want. Please email me at: rajaprathap at juble dot com

  5. #5
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    try:
    Code:
    CREATE PROCEDURE account_Login (IN ScrName VARCHAR(50),IN Passwd AS VARCHAR(50) )
    BEGIN
    DECLARE GoodLogin INT(number of digits)
    SELECT UserID INTO GoodLogin FROM Users WHERE ScreenName = ScrName AND Password = Passwd AND Status <> 0;
    IF GoodLogin IS NOT NULL THEN
    	UPDATE Users SET LastLogin = CURDATE() WHERE UserID = GoodLogin;
    END IF;
    
    SELECT * FROM Users WHERE ScreenName = ScrName AND Password = Passwd AND Status <> 0;
    END
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •