This code sample illustrates the uses of if-conditions in a stored procedure in databases.
create PROC [dbo].[usp_category_sel] ( @category_name varchar(200)=null, @cat_id int=null )
AS BEGIN if @category_name is not null begin SELECT cat_id,category_name,status FROM category where category_name=@category_name end
else if((@cat_id is not null)and (status is not null)) begin SELECT cat_id,category_name,status FROM category WHERE cat_id=@cat_id end
else BEGIN SELECT cat_id,category_name,status FROM category where status='true' END END
|
No responses found. Be the first to respond and make money from revenue sharing program.
|