Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 34083 |  Welcome, Guest!   Register  Login
 Home > Forums > Sql Server > How to write store Procedure ...
Gow.net

How to write store Procedure

Replies: 12 | Posted by: Gow.net on 2/16/2012 | Category: Sql Server Forums | Views: 469 | Status: [Member] | Points: 10  


How to write store Procedure For below query

select brand,model,rating,sum(rate)as ModelRank from dellfeedback WHERE commands like '%l%' and commands like '%l%'or commands like '%l%' and rating !='Poor'and rating !='Not Poor'GROUP BY model,rating,brand union all  select brand,model,rating,sum(rate)as ModelRank from Sonyfeedback WHERE commands like '%l%' and commands like '%l%'or commands like '%l%' and rating !='Poor'and rating !='Not Poor'GROUP BY model,rating,brand


gowthaman8870226416


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Swapnil
Swapnil  
Posted on: 2/16/2012 7:36:29 AM
Level: Starter | Status: [Member] | Points: 25

Here you go.
CREATE PROCEDURE sp_myStoredProcedure

AS

select brand,model,rating,sum(rate)as ModelRank from dellfeedback WHERE commands like '%l%' and commands like '%l%'or commands like '%l%' and rating !='Poor'and rating !='Not Poor'GROUP BY model,rating,brand union all select brand,model,rating,sum(rate)as ModelRank from Sonyfeedback WHERE commands like '%l%' and commands like '%l%'or commands like '%l%' and rating !='Poor'and rating !='Not Poor'GROUP BY model,rating,brand

Go


Thanks and Regards,
Swapnil

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Gow.net
Gow.net  
Posted on: 2/16/2012 8:42:45 AM
Level: Starter | Status: [Member] | Points: 25

hi Swapnil sir
thanks for your replay
but how apply this procedure in my application because here i am searching 3 key words
 commands like '%l%' and commands like '%l%'or commands like '%l%' 
so how i pass 3 parameters

gowthaman8870226416

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Swapnil
Swapnil  
Posted on: 2/16/2012 9:38:51 AM
Level: Starter | Status: [Member] | Points: 25

you can add more parameter based on your requirement however from procedure all three parameters are same so i have added 1 parameter based on your requirement.

CREATE PROCEDURE sp_myStoredProcedure

@commands char(1) = null
AS
select brand,model,rating,sum(rate)as ModelRank from dellfeedback WHERE commands like '%l%' and commands like '%l%'or commands like '%l%' and rating !='Poor'and rating !='Not Poor'GROUP BY model,rating,brand union all select brand,model,rating,sum(rate)as ModelRank from Sonyfeedback WHERE commands like '%' + commands + '%' and commands like '%' + commands + '%' or commands like '%' + commands + '%' and rating !='Poor' and rating !='Not Poor'GROUP BY model,rating,brand
Go


Thanks and Regards,
Swapnil

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Sriramnandha
Sriramnandha  
Posted on: 6/26/2012 12:42:40 AM
Level: Starter | Status: [Member] | Points: 25

CREATE PROCEDURE sp_TestProcedure

@proid int,
@proname varchar(90),
@prodesci varchar(90)

AS
select brand,model,rating,sum(rate)as ModelRank from dellfeedback WHERE commands like '%l%' and commands like '%l%'or commands like '%l%' and rating !='Poor'and rating !='Not Poor'GROUP BY model,rating,brand union all select brand,model,rating,sum(rate)as ModelRank from Sonyfeedback WHERE commands like '%l%' and commands like '%l%'or commands like '%l%' and rating !='Poor'and rating !='Not Poor'GROUP BY model,rating,brand

Go


Hope This will help

Regards


sriram

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Ranjeet_8
Ranjeet_8  
Posted on: 6/29/2012 4:07:59 AM
Level: Gold | Status: [Member] | Points: 25



SET ANSI_NULLS ON

GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE dbo.Procedure_Name
@KeyWord1 varchar(50) = null
@KeyWord2 varchar(50) = null
@KeyWord3 varchar(50) = null
AS
BEGIN
select brand,model,rating,sum(rate)as ModelRank from dellfeedback WHERE commands like '%@KeyWord1%' and commands like '%@KeyWord2%'or commands like '%@KeyWord3%' and rating !='Poor'and rating !='Not Poor'GROUP BY model,rating,brand union all select brand,model,rating,sum(rate)as ModelRank from Sonyfeedback WHERE commands like '%@KeyWord1%' and commands like '%@KeyWord2%'or commands like '%@KeyWord3%' and rating !='Poor'and rating !='Not Poor'GROUP BY model,rating,brand


END
GO

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 6/29/2012 9:52:12 AM
Level: Silver | Status: [Member] | Points: 25

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 6/29/2012 9:52:35 AM
Level: Silver | Status: [Member] | Points: 25

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 6/29/2012 9:59:01 AM
Level: Silver | Status: [Member] | Points: 25

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 6/29/2012 10:05:36 AM
Level: Silver | Status: [Member] | Points: 25

Also mark as answer,if it helps you...

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Muralidosscm
Muralidosscm  
Posted on: 7/3/2012 8:17:26 AM
Level: Starter | Status: [Member] | Points: 25

Create procedure ABC
as
begin
select brand,model,rating,sum(rate)as ModelRank from dellfeedback WHERE commands like '%l%' and commands like '%l%'or commands like '%l%' and rating !='Poor'and rating !='Not Poor'GROUP BY model,rating,brand union all select brand,model,rating,sum(rate)as ModelRank from Sonyfeedback WHERE commands like '%l%' and commands like '%l%'or commands like '%l%' and rating !='Poor'and rating !='Not Poor'GROUP BY model,rating,brand

end

Regards
Muralidoss M

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Pandians
Pandians  
Posted on: 7/3/2012 8:43:31 AM
Level: Silver | Status: [Member] [MVP] | Points: 25

You can use Table type parameter...
Use <Database Name>

Go

/*Creating User Defined Table Type*/
If TYPE_ID('Rating') Is Null
CREATE TYPE Rating AS TABLE(
Rating varchar(100)
)
GO

/*Creating Stored Procedure having Two parameters*/
If OBJECT_ID('Usp_Feedback') Is Not Null
Drop Proc Usp_Feedback
Go
Create Proc Usp_Feedback
(
@Commands Varchar(10),
@Rating Rating Readonly
)
As
Begin
Set Nocount On

select brand,model,rating,sum(rate)as ModelRank from dellfeedback
WHERE commands like '%' + @Commands + '%'
and rating Not In (Select Rating From @Rating)
GROUP BY model,rating,brand
union
select brand,model,rating,sum(rate)as ModelRank from Sonyfeedback
WHERE commands like '%' + @Commands + '%'
and rating Not In (Select Rating From @Rating)
GROUP BY model,rating,brand
End
Go

/*Executing the Stored procedure*/
Declare @Rating Rating

Insert @Rating Values('Poor')
Insert @Rating Values('Not Poor')

Exec Usp_Feedback '1',@Rating
Go


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Perfect.Chourasia@Gmail.Com
Perfect.Chourasia@Gmail.Com  
Posted on: 7/4/2012 4:49:24 AM
Level: Starter | Status: [Member] | Points: 25

Above answer is correct .So update the result (Set resolved)

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://sandeep-chourasia.blogspot.com/

Gow.net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

Found interesting? Add this to:


 Latest Posts

Write New Post | More ...

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/19/2013 7:32:19 AM