Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 238053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:28:30+00:00 2026-05-11T20:28:30+00:00

Trying to migrate from MSSQL to MySQL. This Stored Proc is creating a temp

  • 0

Trying to migrate from MSSQL to MySQL. This Stored Proc is creating a temp table for some columns from a permanent table then using a cursor to update each record’s RandNum column with a random number and selects the dataset. As I’m writing this I thought that I could bypass the cursor and just…

SELECT Id, Title, DateStart, Rand() FROM cms_News;

But i dont want to change anything too drastic, because right now I’m just trying to convert the DB. I will go back and optimize this stuff later. Here’s the SP: EDIT: I removed all of the code from this example that has nothing to do with the error. Also, I saw this online today and it seems that I’m not the only one who is having this issue. MySQL does not like the syntax of my cursor declaration. Any Ideas?

DELIMITER ;//

DROP PROCEDURE IF EXISTS `cms_NewsSelectMainPageNews`;//
CREATE PROCEDURE `cms_NewsSelectMainPageNews`
()
BEGIN
  CREATE TEMPORARY TABLE tempNews
  (
    Id int NOT NULL, 
    Title nvarchar(250),
    DateStart datetime,
    RandNum float NULL
  );

  DECLARE Randomizer CURSOR
      FOR SELECT Id FROM tempNews;
END;//
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:28:30+00:00Added an answer on May 11, 2026 at 8:28 pm
      REPEAT
        FETCH Randomizer INTO cursor_id;
        IF NOT done THEN
          UPDATE tempNews SET RandNum = rand();
           WHERE id = @cursor_id;
        END IF;
      UNTIL done END REPEAT;
    

    You are using unitialized session variable @cursor_id instead of procedure-declared variable cursor_id

    Rewrite as follows:

      REPEAT
        FETCH Randomizer INTO cursor_id;
        IF NOT done THEN
          UPDATE tempNews SET RandNum = rand();
           WHERE id = cursor_id;
        END IF;
      UNTIL done END REPEAT;
    

    or even better, just get rid of your temporary table at all, as you suggested in the first place.


    As for this statement:

    But i dont want to change anything too drastic, because right now I’m just trying to convert the DB. I will go back and optimize this stuff later.

    SQL Server and MySQL are vastly different platforms.

    You’ve already changed everything too drastic when decided to switch.

    In most cases you can’t just copy your old code and hammer it to MySQL.

    It would possibly work between several versions of SQL Server, since at least there are attempts to maintain some kind of compatibility between the versions of same platform, but this definitely won’t work for porting to MySQL.

    What I would do is take every piece of your code and make sure it produces the same results as the old code did, using methods as simple and predictable as possible.

    In your case, the @cursor_id variable could be initialized earlier in the code and its value could be used by the stored procedure, which would lead to any kind of unexpected behaviour.

    This is because in SQL Server the variables have batch scope, while in MySQL they have session scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 334k
  • Answers 334k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer See added comment inlined... You code is fine except for… May 14, 2026 at 3:20 am
  • Editorial Team
    Editorial Team added an answer Actually you cannot download a pdf via XMLHttpRequest (AJAX). In… May 14, 2026 at 3:20 am
  • Editorial Team
    Editorial Team added an answer bmoaskau your solution is good i prefer to do this… May 14, 2026 at 3:20 am

Related Questions

I'm trying to migrate a MySQL-based app over to Microsoft SQL Server 2005 (not
I am trying to use a Rake task to migrate some legacy data from
I've got a users table and a votes table. The votes table stores votes
I've just wasted the past two hours of my life trying to create a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.