存储过程不好用!
我的存储过程如下:
create proc seniorsearch
@sex varchar(2),
@age1 tinyint,
@age2 tinyint,
@height int=null,
@weight int=null,
@education varchar(50)=null,
@location varchar(50)=null,
@hasmarried varchar(4)=null,
@hasphoto varchar(4)=null,
@salary int=null,
@hashouse varchar(4)=null,
@jobtype varchar(50)=null
as
select * from Account a join Maindetail b on a.userid=b.userid join Moredetail c
on a.userid=c.userid
where b.sex=@sex and b.age> @age1 and b.age <@age2 and b.height=isnull(@height,height)
and b.weight=isnull(@weight,weight) and b.education=isnull(@education,education)
and b.location=@location and c.hasmarried=isnull(@hasmarried,hasmarried)
and c.hasphoto=isnull(@hasphoto,hasphoto) and b.salary=isnull(@salary,salary)
and c.hashouse=isnull(@hashouse,hashouse) and b.jobtype=isnull(@jobtype,jobtype)
go
执行以后查不到数据,但是用相同条件的查询语句却能查到数据,大家帮我看看哪块的问题?
------解决方案--------------------相同条件的查询语句也帖出来
------解决方案--------------------写个视图吧
------解决方案--------------------tinyint型是从 0 到 255 的整型数据。存储大小为 1 字节。
你的 '18 '和 '50 '都是2个字节,会不会是这个原因?
------解决方案--------------------兩個語句還是有些區別,一個有=,一個沒有
運行這個
select * from Account a join Maindetail b on a.userid=b.userid join Moredetail c
on a.userid=c.userid
where b.sex= '男 ' and b.age> '18 ' and b.age < '50 ' and b.location= '大连市 '
看看有沒有結果
------解决方案--------------------@hasmarried varchar(4)=null, 先试一试把这些去掉,就是说,用顾定的试一试