存储过程有三个输入参数:部门编码,月份,日期。我想在存储过程里实现如果只输入部门参数,就取当天的月份和日期下的部门情况;也可以输入月份日期参数,查询某月某日的部门情况。存储过程里的输入参数的默认值只能为常量,而当天月份只能用函数变量表示,请问该怎么解决?
create proc 名
@编码 char(10),
@月份 char(2),
@日期 char(2)
as
select * from table where 编码=@编码 and
month(date字段)=isnull(@月份,month(getdate())) and day(date字段)=isnull(@日期,day(getdate()))
名 10001,null,null
名 10001,04,06
create proc 名
@编码 int,
@月份 int=null,
@日期 int=null
as
select * from 表 where @编码=编码 and isnull(@月份,month(getdate())),isnull(@日期,day(getdate()))