MSSQL server database stored procedures converted to MySQL database (1/2)

Source: Internet
Author: User
Tags mssql mssql server mysql tutorial prepare stmt

MSSQL Server database tutorial stored procedures converted into MySQL tutorial database

DELIMITER $$
DROP PROCEDURE IF EXISTS changesequence$$
CREATE PROCEDURE changesequence
(
_sign INT,--0: Move up 1: Move Down
Table Name of TableName VARCHAR (m),--
ItemName VARCHAR,--primary key field name
ItemID INT,--primary Key ID
Sortname VARCHAR (50),--Sort ID
TypeName VARCHAR (50),--category field name
Typevalue VARCHAR (50)--Classification value
)
BEGIN
DECLARE _sql VARCHAR (4000);
DECLARE Thissort INT;
DECLARE Previd INT;
DECLARE NextID INT;
DECLARE _count INT;

CREATE Temporary TABLE _tab
(
_itemid INT,
_sort INT
);
SET _sql=concat (' INSERT into _tab (_itemid,_sort) SELECT ", Itemname,sortname, ' from ', TableName);

IF (typename<> ' and typevalue<> ') THEN
SET _sql=concat (_sql, ' where ', TypeName, ' = ', typevalue);
End IF;
SET _sql = CONCAT (_sql, ' ORDER by _sort ASC ');
SET @v_sql =_sql;
PREPARE stmt from @v_sql;
EXECUTE stmt;
Deallocate PREPARE stmt;
SET _sql = ';

Home 1 2 last page
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.