Replies |
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
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
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
|
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
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
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
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
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
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
|
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
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
|
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
|