我想在mysql中编写存储过程,我想在其中添加“where子句” 动态 我写了Sp但是给了它一个错误 请帮忙
CREATE PROCEDURE GetStudent(
@Center varchar(20)=null,
@Gender varchar(20) = null,
@yrOf10 date= null,
@Designation varchar(20)= null,)
AS DECLARE @Query VARCHAR(100);DECLARE @ParamDefinition NVARCHAR(2000);
SET @Query = ' SELECT * FROM Student WHERE 1=1';IF @Center IS NOT NULL
SET @Query = @Query + ' AND Center= @Center ';IF @Gender IS NOT NULL SET @Query = @Query + ' AND Gender=@Gender ';IF @yrOf10 IS NOT NULL SET @Query = @Query + ' AND yrOfPassing10=@yrOf10 ';IF @Designation IS NOT NULL SET @Query = @Query + ' AND Designation=@Designation';
答案 0 :(得分:0)
您无法在对象名称http://dev.mysql.com/doc/refman/5.0/en/identifiers.html中使用@符号。
我不知道你为什么要用@作为前缀。你是从MS SQL开始的吗?
无论如何要对本地变量进行decalre,请使用DECLARE http://dev.mysql.com/doc/refman/5.0/en/declare-local-variable.html