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

  • SEARCH
  • Home
  • 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 8264567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:30:25+00:00 2026-06-08T04:30:25+00:00

I’m trying to setup a demo of some software for a client and need

  • 0

I’m trying to setup a demo of some software for a client and need live reporting data to do so. This is business software that will rely on information that would normally reside in an ERP type system where there are sales orders and purchase orders (and all the data to build those things).

I looked long and hard for a sample ERP database and the only thing I could come up with was MySQL port of the MS AdventureWorks DB. This is great and has a lot of data I can use to sample.

The problem is, all the dates on the orders are from 2001-2004.

What I’d like to do is write a simple MySQL script that will loop through every datetime field in the entire AdventureWorks DB and add 10 years to it. This will make the date range (2011-2014), which is much more reasonable.

I found this post that had a very similar script I thought I could borrow from, but for some reason I can’t seem to port it over to MySQL.

I’ve boiled it down to this little piece of code. For some reason, my MySQL will not run the WHILE loop – and I am clueless why.

USE adventureworks;

CREATE TEMPORARY TABLE ColumnList 
       (
      TableName NVARCHAR (100),
      columnName NVARCHAR (100)
       );


INSERT INTO ColumnList
        select t.table_name,c.column_name
        from information_schema.tables t inner join information_schema.columns c on t.table_name=c.table_name
        where c.column_type = 'datetime';

SET @Counter = 1;
SET @TotalCount = (SELECT COUNT(*) FROM ColumnList C);

BEGIN
    -- do stuff here
    @Counter = @Counter + 1;
END
END WHILE;

Error that comes out:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHILE @Counter <= @TotalCount DO
BEGIN
  -- do stuff here
END
END WHILE' at line 1

Any help would be appreciated.

Final Update
* The answer below was right, but in case anywhere stumbled upon this looking for an answer, I couldn’t find one without getting very complicated with prepared statements/etc because I couldn’t build the dyanmic SQL in MySQL. I ended up writing this little script inside my CodeIgniter app to handle it.

Hope it helps someone down the line:

$this->load->database();    

$sql = "select t.table_name,c.column_name
from information_schema.tables t inner join information_schema.columns c on t.table_name=c.table_name
where c.table_schema='adventureworks' and c.column_type = 'datetime';";

$columnlist = $this->db->query($sql);

foreach ($columnlist->result_array() as $row) 
{
  //Now you have list of columns and tables, need to go in to each table, get all
  //results and update
  $column = $row['column_name'];
  $table = $row['table_name'];

  $sql = 
    "select distinct $column as 'thisdate', DATE_ADD($column, INTERVAL 10 YEAR) as 'newdate'
    from $table";

  $valuelist = $this->db->query($sql);
  $results = $valuelist->result_array();

  foreach ($results as $value) 
  {        
    $thisdate = date ("Y-m-d H:i:s", strtotime($value['thisdate']));
    $newdate = date ("Y-m-d H:i:s", strtotime($value['newdate']));

    $updatestmt =
      'update '.$table.' set '.$column." = '". $newdate ."' where $column = '".$thisdate."'";

    echo $updatestmt;
    $this->db->query($updatestmt);
    echo ' -- rows affected '.$this->db->affected_rows().'<br/>'; 
  }
}
  • 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-06-08T04:30:28+00:00Added an answer on June 8, 2026 at 4:30 am

    You can only use a while loop in a stored procedure, function or a trigger.
    Your code snippet does not seem to be a part of any such sp or trigger.
    And hence is the error.

    Please refer to WHILE Syntax for more details.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I know there's a lot of other questions out there that deal with this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.