CREATE PROCEDURE GET_T_STAFF
(
@_StaffCode INT
)
AS BEGIN
declare @_sql varchar(100)
set @_sql='select'
set @_sql=@_sql+' StaffCode,LoginPw,StaffName,Sex,IDCode,GraduateSchool,EntryDate,IfStop FROM dbo.T_Staff WHERE 1=1'
if @_StaffCode >=1
begin
set @_sql=@_sql+' and StaffCode=@_StaffCode'
end
print @_sql
end
这里GET_T_STAFF 输入参数 并没有进入IF判断 求解释
------解决方案--------------------
- SQL code
CREATE PROCEDURE GET_T_STAFF @_StaffCode as INTAS BEGIN declare @_sql as varchar(800) set @_sql = 'select' set @_sql = @_sql + ' StaffCode , LoginPw , StaffName , Sex , IDCode , GraduateSchool , EntryDate , IfStop FROM dbo.T_Staff WHERE 1 = 1 ' if @_StaffCode >=1 set @_sql=@_sql + ' and StaffCode = ' + ltrim(@_StaffCode) print @_sqlend