存储过程模糊查询
1 ALTER proc [dbo].[proc_SelectEInfo] 2 ( 3 @id varchar (20), 4 @name varchar (30), 5 @sex char (4) 6 ) 7 as 8 if(@id='' and @name='' and @sex='') 9 select * from tb_Employee 10 else 11 begin 12 if(@id<>'') 13 --if (@id<>'' or @name<>'' or @sex<>'') 14 select * from tb_Employee where ID like '%['+@id+']%' 15 else if(@name<>'') 16 select * from tb_Employee where Name like '%['+@name+']%' 17 else 18 select * from tb_Employee where Sex=@sex 19 end
多表查询
1 ALTER PROCEDURE [dbo].[proc_SchHrkh] 2 -- Add the parameters for the stored procedure here 3 @t1 datetime, 4 @t2 datetime 5 AS 6 BEGIN 7 -- SET NOCOUNT ON added to prevent extra result sets from 8 -- interfering with SELECT statements. 9 SET NOCOUNT ON; 10 11 -- Insert statements for procedure here 12 -- 13 SELECT h.id 单据编号, h.employid as 员工ID,p.psnName as 姓名, b.department as 部门,h.kctime as 日期,h.shijian as 原因,h.fakuan as 金额,h.remark as 备注 14 FROM (SELECT * FROM hrms_jilv_kaocha WHERE kctime>= @t1 AND kctime<=@t2) as h, person as p, base_department as b where h.did=b.id and h.employid=p.id 15 group by h.kctime,b.department,h.id,h.did, h.employid,p.psnName,h.kctime,h.shijian,h.fakuan,h.remark 16 order by h.kctime desc 17 END
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号