当前位置: 代码迷 >> Sql Server >> 关于存储过程 if else解决思路
  详细解决方案

关于存储过程 if else解决思路

热度:89   发布时间:2016-04-27 13:41:10.0
关于存储过程 if else
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
  相关解决方案