sqlserver存储过程demo


/*
SQL sertver 存储过程 的示例:用@@rowcount返回查询结果总数,
程序调用方法为:
selectByStoreProcedure("{ ?=call proc_demo_students(?,?,?,?) }", paramsArray, pageSize, currentPage,3,false);
*/
ALTER PROCEDURE [dbo].[proc_demo_students]
@sname char(10) = '',
@sgender char(1) = '',
@Phone varchar(11),
@Extension varchar(10) = ''
AS
set @Phone = isnull(@Phone, '')
set @Extension = isnull(@Extension, '')
set @sname = isnull(@sname, '')
begin
select c.id,c.SurName,c.FirstName,cm.ContactNo,
case c.Gender when 'M' then '男' when 'F' then '女' end as Gender
from Customer c
left join ContactMethod cm
on c.id = cm.CustomerId
where ((@Phone='') or (cm.ContactNo like '%' + @phone + '%'))
and ((@Extension='') or (cm.Extension like '%' + @Extension + '%'))
and ((@sname='') or ((rtrim(ltrim(c.surname))+rtrim(ltrim(c.firstName))) = @sname))
and cm.Channel = @sgender
end
return @@rowcount

你可能感兴趣的:(数据库-存储过程)