注册 登录
编程论坛 SQL Server论坛

请教多条件查询的存储过程

tan502407 发布于 2008-10-20 17:34, 1544 次点击
一个表student有5个字段:studentId,studentName,studentSex,studentAge,department
用一个sql语句查询的话是这样:select * from student where studentId="123456"
现在我想做一个存储过程实现动态改变查询条件, 比如改成select * from student where studentName="654321"
就是说存储过程有2个参数,一个影响"="左边,一个影响"="右边。这要怎么操作?
6 回复
#2
tan5024072008-10-20 17:36
拼接语句可以吗?怎么做呀~
#3
tan5024072008-10-21 08:32
没人回复啊~~~-_-!
#4
donadonny2008-10-21 09:06
没看懂你最后一句话的意思
没接触sql很多年了,都忘了,帮你顶一下吧
#5
西风独自凉2008-10-21 13:02
看不懂是什么意思
#6
tan5024072008-10-21 14:11
呵。麻烦各位了。~
解决了这个问题。拼接出来的。还是谢谢各位~
#7
happynight2008-10-21 16:28
Create Procedure Test (@intType  bit,@strValue  varchar(10))
AS
IF intType=0
  select * from student where studentId=@strValue
else
  select * from student where studentName=@strValue
1