Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sqlnewbie10
Starting Member
8 Posts |
Posted - 2010-03-16 : 16:10:41
|
| I need to create a stored procedure where a user can input several values for a given parameter – the logic is as below. Is there a way of doing this without seperating the parameter values with a comma? E.g the user will execute the procedure as EXECUTE dbo.GetClientDetails '1 3 4'And get the same results...CREATE PROC dbo.GetClientDetails( @ID varchar(500))ASBEGIN SET NOCOUNT ON DECLARE @GetAll varchar(600) SET @GetAll = 'SELECT * FROM dbo.Client WHERE ClientId IN (' + @ID + ')' EXEC(@GetAll) ENDGOEXECUTE dbo.GetClientDetails '1,3,4'Thanks |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2010-03-16 : 17:19:00
|
| when executing procedure one must declare input parameter(s). if you want to use solely one, take into consideration to have either a function | subprocedure to split input string and read all the relevant data and run it within procedure. |
 |
|
|
sqlnewbie10
Starting Member
8 Posts |
Posted - 2010-03-16 : 17:24:50
|
quote: when executing procedure one must declare input parameter(s). if you want to use solely one, take into consideration to have either a function | subprocedure to split input string and read all the relevant data and run it within procedure.
@slimt_slimtDo you have an example of something like this |
 |
|
|
namman
Constraint Violating Yak Guru
285 Posts |
Posted - 2010-03-16 : 17:26:17
|
| For quick solution .... Using replace function to replace ' ' to ','Try to see if it works for you. EXECUTE dbo.GetClientDetails '1 3 4'CREATE PROC dbo.GetClientDetails(@ID varchar(500))ASBEGINSET NOCOUNT ONDECLARE @GetAll varchar(600)SET @ID = replace(@ID, ' ', ',')SET @GetAll ='SELECT *FROM dbo.ClientWHERE ClientId IN (' + @ID + ')'EXEC(@GetAll)ENDGO |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|