1

我想弄清楚是什么意思

execute('SELECT customerID [CustomerID],customerCode[Customer Code],
firstName +char(32)+ surname AS [Name],street [Street],phone [Phone],*  
FROM tblCustomers  WHERE customerCode like '''+ @custCode +'%''')

在存储过程中。我试图用谷歌搜索这么多,但无法找到,所以最后我来这里寻求帮助。因为,我正在将 SP 从 MS SQL 转换为 MySQL,我如何在 MySQL 中翻译它?Execute(' select * from tablename') 和 'select * from tablename' 之间有什么区别吗?

谢谢

4

1 回答 1

0
SET @sql = CONCAT(' SELECT      *,
                            customerID,
                            customerCode `Customer Code`,
                            CONCAT(firstName, ' ', surname) AS `Name`,
                            street `Street`,
                            phone `Phone` 
                    FROM tblCustomers  
                    WHERE customerCode like ''', @custCode ,'%''');

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

或参数化它,

SET @sql = '    SELECT      *,
                        customerID,
                        customerCode `Customer Code`,
                        CONCAT(firstName, ' ', surname) AS `Name`,
                        street `Street`,
                        phone `Phone` 
                FROM tblCustomers  
                WHERE customerCode LIKE CONCAT(?, ''%'')';

PREPARE stmt FROM @sql;
EXECUTE stmt USING @custCode;
DEALLOCATE PREPARE stmt;
于 2013-02-08T02:53:22.360 回答