在存储过程中如何判断参数是字母还是数字
有这样一个存储过程:
CREATE PROCEDURE [doctor_name]
@p varchar(20)
AS
select doctorname from doctor where doctorpym like @p+'%'
return
GO
现在想改为先判断接受的参数@p是字母还是数字,如果是字母就就执行:
select doctorname from doctor where doctorpym like @p+'%'
是数字就执行:
select doctorname from doctor where doctorcfh like @p+'%'
注意:doctorcfh 是int型,而doctorpym是varchar型
------解决方案--------------------
SQL code
--你要是怕出错,都转成字符串就ok了。
create procedure [doctor_name]
@p varchar(20)
as
select doctorname from doctor
where doctorpym like @p+'%'or ltrim(doctorcfh) like @p+'%'