Asp.net modules
  • Home
  • c# Modules
  • Web Design
    • Html
    • Css
    • Java Script
  • Bootstrap
  • Sql
    • Queries
    • Stored Procedures
  • About Me
    • About Myself
    • My Projects
    • My Resume
  • Photo Gallery

Thursday, November 26, 2015

stored procedure with case and actions

 Unknown     4:43 AM     sp     No comments   

Intoduction :-

Hii Friends...

Today I explain how to use case and action in stored procedure . 


CREATE Proc [dbo].[Proc_ManageRatingAndReview]--exec [Proc_ManageRatingAndReview] 'GetAllBySeller','','','101647'                
(                           
@Action nvarchar(50)='',                           
@ID int=0,       
@ProductID int=0,       
@SellerMsrNo int=0                          
)                           
as                           
begin                           
                            
if(@Action='Delete')                           
begin                           
delete tblRatingAndReview Where RatingAndReviewID = @ID                           
end                           
                            
                                 
if(@Action='IsActive')                           
begin                           
update tblRatingAndReview set IsActive=case when IsActive=0 then 1 else 0 end                            
where RatingAndReviewID=@ID                           
end                           
                            
                            
if(@Action='GetAll')                           
begin                           
Select * from tblRatingAndReview                            
where RatingAndReviewID= case when @ID=0 then RatingAndReviewID  else @ID  end  order by ProductID desc                           
end                         
                            
                         
if(@Action='Get')                           
begin                           
Select * from tblRatingAndReview                           
where RatingAndReviewID= case when @ID=0 then RatingAndReviewID else @ID  end and  IsActive='true'  order by ProductID desc                               
end      
     
if(@Action='GetAllBySeller')                           
begin                           
Select distinct IV.ProductName,RAR.*,MM.FirstName+' '+MM.LastName as SellerName from tblRatingAndReview as RAR    
inner join tblInvoiceDetail as IV on RAR.ProductID=IV.ProductID    
inner join tblMlm_memberMaster as MM on RAR.SellerMsrNo= MM.MsrNo                        
where RAR.SellerMsrNo= case when @SellerMsrNo=0 then RAR.SellerMsrNo  else @SellerMsrNo  end  order by RAR.ProductID desc                           
end    
                          
                       
                       
if(@Action='GetByProductID')                           
begin                           
Select RatingAndReviewID, ReviewTitle, YourReview, CONVERT(decimal(5,0),YourRating)as YourRating,IPAddress, ProductID, UserName, UserEmail, AddDate, LastUpdate, IsActive from tblRatingAndReview                           
where ProductID= case when @ProductID=0 then ProductID else @ProductID  end       
and SellerMsrNo= case when @SellerMsrNo=0 then SellerMsrNo else @SellerMsrNo  end       
and  IsActive='true' order by ProductID,AddDate desc                               
end                         
                   
                   
if(@Action='GetRating')                       
begin                       
                   
declare @Rating decimal(5,0)                   
select @Rating=ROUND(AVG(YourRating), 0) FROM tblRatingAndReview where ProductID=                   
 case when @ID=0 then ProductID                   
 else @ID                   
 end and  IsActive='true'                   
                   
if @Rating>0                   
begin                    
 select @Rating as Rating                   
end                   
else                   
begin                   
 select 4 as Rating                   
end                   
                   
                   
end                               
end
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Popular Posts

  • Asp.net insert, Edit, update, delete in grid view
    Introduction :   Here I explain how to insert, edit, update and delete data in grid view using asp.net. In this project I use so...
  • Angular Expressions
    Intoduction :-   Hii Friends... Today I explain about angular js expressions. this is similar to JavaScript expressions. 1) The expr...
  • Basic of css.
    Introduction :- Hii Friends..   Today I explain what is Css and why we use Css and the basic structure of css. so here I               ...
  • How to create pikachu character using HTML & CSS
    Hii Friends... Today I explain how to create cartoon( Pikachu character) using HTML and CSS . you can use this code in your project cop...
  • stored procedure with case and actions
    Intoduction :- Hii Friends... Today I  explain how to use case and action in stored procedure .  CREATE Proc [dbo].[Proc_ManageRatingA...
  • Css hovering fill circle boundary
    Intoduction :-   Hii Friends... Today I explain how to make css hovering fill circle. hover selector is used to select elements when you ...
  • How To Make Semi-Transparent Buttons
    Intoduction :-   Hii Friends...   Today I explain how to make Semi-Transparent Buttons with the help of css. This style now a days goes t...
  • How to create Animation Using HTML & CSS
    Hii Friends... Today I explain how to create Animations using HTML and CSS . you can use this code in your project copy this code and p...
  • How To Create Image wipe Effect With CSS3 Webkit Animation
    Intoduction :- Hii Friends...   Today I explain how to create a Image wipe effect with CSS3. CSS transition and animations provide a w...
  • Create a Cart Popup div in HTML & CSS
    Intoduction :-   Hii Friends... Today I explain how to Create a Cart Popup div in HTML & CSS . This moduel base on mouse hover when y...

Blog Archive

  • ►  2017 (13)
    • ►  December (1)
    • ►  March (5)
    • ►  February (1)
    • ►  January (6)
  • ►  2016 (31)
    • ►  November (1)
    • ►  September (1)
    • ►  June (6)
    • ►  May (3)
    • ►  April (2)
    • ►  March (8)
    • ►  February (9)
    • ►  January (1)
  • ▼  2015 (31)
    • ►  December (3)
    • ▼  November (4)
      • stored procedure with case and actions
      • Some tricks for stored procedures
      • How to make ck editor in Asp.net
      • How to get a table Script
    • ►  October (18)
    • ►  September (6)

About Me

Unknown
View my complete profile

Copyright © Asp.net modules | Powered by Blogger
Design by Sheetal Khandelwal