dbTalk Databases Forums  

How do I Pass set of strings to Stored procedure WHERE IN clasue

comp.databases.sybase comp.databases.sybase


Discuss How do I Pass set of strings to Stored procedure WHERE IN clasue in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
rpmohan
 
Posts: n/a

Default How do I Pass set of strings to Stored procedure WHERE IN clasue - 02-02-2004 , 11:04 PM






Hello All,
We have stored procedure which will receive set of names and birth
date of the candidate
CREATE PROCEDURE ml_test_student
@nameStr varchar(255),@dateStr
AS
SELECT distinct s.StudentID, "|", s.Name, "|", s.birthdate,"|",
IsValid FROM
Student s
WHERE Id in (@nameStr) and birthdate < @dateStr ORDER by Name

Execution ---->
For single name
exec ml_test_fasb 'raju' '19980401'

Result: 1 rows retrieved.

If i need to pass multiple names on the namestr what should I do.. is
any changes are required in existing procedure definiton...
or else i should use temporary table...

If i should use temp table... how do I parse the string and insert
into table..

Could any one help me on this... Please...

Reply With Quote
  #2  
Old   
Kristian Damm Jensen
 
Posts: n/a

Default Re: How do I Pass set of strings to Stored procedure WHERE IN clasue - 02-03-2004 , 01:01 AM






rpmohan wrote:
Quote:
Hello All,
We have stored procedure which will receive set of names and birth
date of the candidate
CREATE PROCEDURE ml_test_student
@nameStr varchar(255),@dateStr
AS
SELECT distinct s.StudentID, "|", s.Name, "|", s.birthdate,"|",
IsValid FROM
Student s
WHERE Id in (@nameStr) and birthdate < @dateStr ORDER by Name

Execution ----
For single name
exec ml_test_fasb 'raju' '19980401'

Result: 1 rows retrieved.
What you in effect are executing is

SELECT distinct s.StudentID, "|", s.Name, "|", s.birthdate,"|", IsValid
FROM Student s
WHERE Id in ('raju') and birthdate < '19980401'
ORDER by Name

Quote:
If i need to pass multiple names on the namestr what should I do.. is
any changes are required in existing procedure definiton...
or else i should use temporary table...
You've got to options:
(1) Deconstruct the strong and put the elements of the string into a temporary table. (It is not as difficult as it may sound.)
(2) Look into dynamic sql. Some version af Sybase SQLServer support EXEC @string, where @string contains an SQL-statement. (Sometimes unofficially, mind you.)

Quote:
If i should use temp table... how do I parse the string and insert
into table..
charindex will find the position to split the string, substring will help you do the splitting.

--
Kristian Damm Jensen
damm (at) ofir (dot) dk


Reply With Quote
  #3  
Old   
Ram DSL
 
Posts: n/a

Default Re: How do I Pass set of strings to Stored procedure WHERE IN clasue - 02-09-2004 , 09:08 AM



You can use the following too...

exec ml test fasb "'raju','ram','mark','shame'",'19980401'

Try it...
Ram DSL


"Kristian Damm Jensen" <REdammMOVE (AT) ofir (DOT) dk> wrote

Quote:
rpmohan wrote:
Hello All,
We have stored procedure which will receive set of names and birth
date of the candidate
CREATE PROCEDURE ml test student
@nameStr varchar(255),@dateStr
AS
SELECT distinct s.StudentID, "|", s.Name, "|", s.birthdate,"|",
IsValid FROM
Student s
WHERE Id in (@nameStr) and birthdate < @dateStr ORDER by Name

Execution ----
For single name
exec ml test fasb 'raju' '19980401'

Result: 1 rows retrieved.

What you in effect are executing is

SELECT distinct s.StudentID, "|", s.Name, "|", s.birthdate,"|", IsValid
FROM Student s
WHERE Id in ('raju') and birthdate < '19980401'
ORDER by Name

If i need to pass multiple names on the namestr what should I do.. is
any changes are required in existing procedure definiton...
or else i should use temporary table...

You've got to options:
(1) Deconstruct the strong and put the elements of the string into a
temporary table. (It is not as difficult as it may sound.)
(2) Look into dynamic sql. Some version af Sybase SQLServer support EXEC
@string, where @string contains an SQL-statement. (Sometimes
unofficially, mind you.)

If i should use temp table... how do I parse the string and insert
into table..

charindex will find the position to split the string, substring will
help you do the splitting.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.