![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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.. |
#3
| |||
| |||
|
|
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. |
![]() |
| Thread Tools | |
| Display Modes | |
| |