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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-07-15 : 08:24:10
|
Michael writes "I have 3 tables, jobs, job_locations and jobs_job_locations lookup table.Jobs job_locations jobs_job_locationsjob_id job_location_id job_iddescription description job_location_id so that in jobs_job_locations I can have a job with multi job_locations.so my select would beCREATE procedure FindJob@job_locsvarchar(50)asselect * from jobs a, job_locations b, jobs_job_locations c where a.job_id=c.job_id and b.job_location_id=c.job_location_id and c.job_location_id in (@job_locs)goif I run exec findjob '1' it works, but when I runfindjob '1,2' it bombs out since it will try to convert '1,2' into a integer. What can I do to make this work? DB engine is MS SQL 2000.thanksmikec" |
|
|
dsdeming
479 Posts |
Posted - 2003-07-15 : 08:34:34
|
| I've always had better luck with CHARINDEX. You could try something like this:CREATE PROCEDURE FindJob @job_locs varchar(50) ASSET @job_locs = ',' + @job_locs + ','SELECT * FROM jobs a, JOIN jobs_job_locations c ON a.job_id=c.job_id JOIN job_locations b ON b.job_location_id=c.job_location_idWHERE CHARINDEX( ',' + CAST( c.job_location_id AS varchar( 12 )) + ',', @job_locs ) > 0go Dennis |
 |
|
|
|
|
|
|
|