Click to See Complete Forum and Search --> : Stored Procedure Multiple Parameters?
terbs
03-30-2007, 12:25 AM
Is there a way to create a stored procedure that can take one or more parameters of the same field and return the results??
e.g.
----------------------------------------
CREATE sproc_GetEntriesByStates
@State int
SELECT *
FROM tblRecords
WHERE
tblRecords.State = @State
---------------------------------------
obviously i want to input parameters such as 1 or 1,2,5,6 etc
cheers
drallab
03-30-2007, 01:17 PM
CREATE PROCEDURE dbo.Sproc_Name
@param1 int,
@param2 int,
@param3 int
--add as many parameters as you want, just be sure to end the previous
--parameter with a comma and the last parameter has no comma
as
--example query with multiple parameters
select * from xTABLEx where xColumn1x = @param1 and xColumn2x = @param3 and xColumn3x = @param3
return
:)
terbs
04-26-2007, 09:02 PM
Create PROCEDURE dbo.sproc_GetServiceCalls
@State1 int,
@State2 int,
@State3 int
AS
SELECT *
FROM TABservice
WHERE
State = @State1 AND
State = @State2 AND
State = @State3
RETURN
ive tried this, but its not what im looking for.
in my DB, state is ONE column only. with the record being a 1, 2 or 3..
I need a query where I can enter 1, 2, 3 or 1,2 or 1 or 2,3 for the SAME field.
cheers :)
terbs
04-26-2007, 09:34 PM
Create PROCEDURE dbo.sproc_GetServiceCalls
@State1 int,
@State2 int,
@State3 int
AS
SELECT *
FROM TABservice
WHERE
State = @State1 AND
State = @State2 AND
State = @State3
RETURN
ive tried this, but its not what im looking for.
in my DB, state is ONE column only. with the record being a 1, 2 or 3..
I need a query where I can enter 1, 2, 3 or 1,2 or 1 or 2,3 for the SAME field.
cheers :)
stupid me...
why I used AND in the WHERE clause and not OR is beyond me... thanks drallab
terbs
04-26-2007, 09:57 PM
is there a way to add anouther parameter of a different field to the above stored procedure?
ALTER PROCEDURE dbo.sproc_GetServiceCalls
@State1 int,
@State2 int,
@State3 int,
@Customer varchar
AS
SELECT *
FROM TABservice
WHERE
(State = @State1 OR
State = @State2 OR
State = @State3)
AND
Customer = @Customer
RETURN
I have tried this.. but it doesnt work.
I need the procedure to return result for ONLY the customer parameter AND where state is equal to State1, State2 and/or State3
Cheers
russell
04-26-2007, 11:59 PM
that ought to work. can use in(...) but what u already have should work
ALTER PROCEDURE dbo.sproc_GetServiceCalls
@State1 int,
@State2 int,
@State3 int,
@Customer varchar(255)
AS
SELECT *
FROM TABservice
WHERE Customer = @Customer
AND State in(@State1, @State2, @State3)
GO