SQLServer存储过程

create proc [dbo].[PhoneRec] (@haoma varchar(32),@ser varchar(16) output)
as
if @haoma='' and @ser=''
begin
select a.serverid,c.serverip,a.filename,b.callernumber,b.callednumber,b.createtime,b.releasetime
from dbo.AGENTRECFILE as a
inner join dbo.COLOG as b
on a.coid=b.coid
inner join dbo.DEVICECFG as c
on a.serverid=c.serverid
order by b.createtime asc
end
else if @haoma=''
begin
select a.serverid,c.serverip,a.filename,b.callernumber,b.callednumber,b.createtime,b.releasetime
from dbo.AGENTRECFILE as a
inner join dbo.COLOG as b
on a.coid=b.coid
inner join dbo.DEVICECFG as c
on c.serverid=@ser and a.serverid=c.serverid
order by b.createtime asc
end
else if @ser=''
begin
select a.serverid,c.serverip,a.filename,b.callernumber,b.callednumber,b.createtime,b.releasetime
from dbo.AGENTRECFILE as a
inner join dbo.COLOG as b
on a.coid=b.coid
inner join dbo.DEVICECFG as c
on a.serverid=c.serverid
where b.callernumber=@haoma or b.callednumber=@haoma
order by b.createtime asc
end
else
begin
select a.serverid,c.serverip,a.filename,b.callernumber,b.callednumber,b.createtime,b.releasetime
from dbo.AGENTRECFILE as a
inner join dbo.COLOG as b
on a.coid=b.coid
inner join dbo.DEVICECFG as c
on c.serverid=@ser and a.serverid=c.serverid
where b.callernumber=@haoma or b.callednumber=@haoma
order by b.createtime asc
end


drop proc PhoneRec

exec PhoneRec 'xxx','yyy'

你可能感兴趣的:(存储过程,sqlserver)