in a stored procedure, when a parameter value is not specified, i want it to display result for all values in the column.
I tried the code as below but if I leave blank the parameter field1 while executing it, it doesn’t work and asks to supply the field1 value.
create procedure procedurename
declare @startdate datetime, @enddate endtime, @field1 varchar(15)
select * from table1
where field1 = @xyz or @xyz is null
and date between @startdate and @enddate
execute procedurename @startdate = '01/07/2012', @enddate = '31/07/2012'
[i omitted field1 value so that it should display result for all values in field1 column between the two dates] but it asks for parameter value.
If you’re going to omit the field on the call, you need to supply a default value in the declaration of the procedure.