Home >Database >Mysql Tutorial >mssql server 数据库存储过程转换成mysql数据库(1/2)

mssql server 数据库存储过程转换成mysql数据库(1/2)

WBOY
WBOYOriginal
2016-06-07 17:47:161265browse

mssql server 存储过程转换成数据库

DELIMITER $$
DROP PROCEDURE IF EXISTS ChangeSequence$$
CREATE PROCEDURE ChangeSequence
(
_sign INT ,-- 0: 上移 1:下移 
TableName VARCHAR(50) ,-- 表名 
ItemName VARCHAR(50) ,-- 主键字段名 
ItemID INT , -- 主键ID 
SortName VARCHAR(50) , -- 排序ID 
TypeName VARCHAR(50) , -- 分类字段名 
TypeValue VARCHAR(50) -- 分类值 
)
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 = '';

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn