下面是我写的一个存储过程演示,可是在
if(@str IS NOT NULL)
select * from student where + @str
这个地方老报错,请问怎么样解决!
create procedure testquery @name char(10),@age int,@sex char(10),@marry char(10)
as
begin
declare @str varchar(500)
declare @leng int
set @str=''
if(@name IS NOT NULL)
set @str='FName=@name and '
if(@age IS NOT NULL)
set @str=@str+'Age=@age and '
if(@sex IS NOT NULL)
set @str=@str+'Sex=@sex and '
if(@marry IS NOT NULL)
set @str=@str+'IsHunFou=@marry and'
set @leng=len(@str)set @str=substring(@str,0,@leng-3)if(@str IS NOT NULL)
select * from student where + @str
else
select * from student
end
if(@str IS NOT NULL)
select * from student where + @str
这个地方老报错,请问怎么样解决!
create procedure testquery @name char(10),@age int,@sex char(10),@marry char(10)
as
begin
declare @str varchar(500)
declare @leng int
set @str=''
if(@name IS NOT NULL)
set @str='FName=@name and '
if(@age IS NOT NULL)
set @str=@str+'Age=@age and '
if(@sex IS NOT NULL)
set @str=@str+'Sex=@sex and '
if(@marry IS NOT NULL)
set @str=@str+'IsHunFou=@marry and'
set @leng=len(@str)set @str=substring(@str,0,@leng-3)if(@str IS NOT NULL)
select * from student where + @str
else
select * from student
end
解决方案 »
- sql语法错误
- sql查询语句问题,在线等!
- 请教多表查询的优化问题。
- 重装操作系统Win2003后,SQL 2000数据库不能附加,已超过了4GB,是不是大小问题?怎样解决呢?先谢了!
- access前端操作程序后台用ODBC连接的sql数据库经常出现连接超时
- 请问2004-12-20 21:15:33 如何转成 20041220211533 反过来又怎样呢?
- 安装MS SQL2000后打不开
- 新手问题
- ●在(ASP+MSSQL)全文本搜索中如何用正则表达式实现类似百度的显示效果?
- oracle的存储过程如何返回结果集?
- 发生错误2 系统找不到指定文件 mssqlserver server服务上执行该服务操作
- 急!~问个数据库问题 请大侠赐教!~
这个地方老报错,请问怎么样解决!exec('select * from student where '+@str)
select * from student where + @str
这个地方老报错,请问怎么样解决!
create procedure testquery @name char(10),@age int,@sex char(10),@marry char(10)
as
begin ...
这位老兄,create 语句必须是批处理语句的第一行,所以应该改为:
if(@str IS NOT NULL)
select * from student where + @str
go
create procedure testquery @name char(10),@age int,@sex char(10),@marry char(10)
as
begin ...