May 4, 2011 at 12:34 pm
create proc usp_Test
(@ID varchar (30),
@code varchar (10),
@startdate smalldatetime = NUll,
@enddate smalldatetime = Null
) as
begin
select * from vw_ABC DB
where @ID = D.ID
and ((@startdate is Null or @enddate is null) or ((Date between @startdate and @enddate)
and ((isnull(@code,'') != '' and DB.Code = @code) or isnull(@code,'') = '')))
END
I created the above stored procedure to return the rows in the following scenarios
pass all the parameters to get result
pass ID and code to get result or
pass ID and date to get result
First 2 scenarios are working fine but when am pasing the ID and date i could not return any rows
Can any one help me with this?
Thanks.
May 4, 2011 at 12:41 pm
ranuganti (5/4/2011)
create proc usp_Test(@ID varchar (30),
@code varchar (10),
@startdate smalldatetime = NUll,
@enddate smalldatetime = Null
) as
begin
select * from vw_ABC DB
where @ID = D.ID
and ((@startdate is Null or @enddate is null) or ((Date between @startdate and @enddate)
and ((isnull(@code,'') != '' and DB.Code = @code) or isnull(@code,'') = '')))
END
I created the above stored procedure to return the rows in the following scenarios
pass all the parameters to get result
pass ID and code to get result or
pass ID and date to get result
First 2 scenarios are working fine but when am pasing the ID and date i could not return any rows
Can any one help me with this?
Thanks.
You need to have the @code variable also set to reurn a null if nothing is passed to it.
create proc usp_Test
(@ID varchar (30),
@code varchar (10) = NULL,
@startdate smalldatetime = NUll,
@enddate smalldatetime = Null
) as
begin
select * from vw_ABC DB
where @ID = D.ID
and ((@startdate is Null or @enddate is null) or ((Date between @startdate and @enddate)
and ((isnull(@code,'') != '' and DB.Code = @code) or isnull(@code,'') = '')))
As it stands you have to pass a value to @Code.
--------------------------------------
When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
--------------------------------------
It’s unpleasantly like being drunk.
What’s so unpleasant about being drunk?
You ask a glass of water. -- Douglas Adams
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply