| Author |
Topic |
|
craigmacca
Posting Yak Master
142 Posts |
Posted - 2010-04-09 : 12:25:42
|
| Hi i have a comma deliminated string of postcodes which i need to pass into a stored proc and then select from a table, i tried this but with no luck, can you halp@PostcodeList nvarchar(2048) = 'le17,cv34,cv30'SELECT dj.EntityId, dj.Title, dj.[Description], dj.MediaCodeId, dj.SubCategoryId, dj.CustomerId, dj.SalaryFromId, dj.SalaryToId, dj.HoursId, dj.ContractTypeId FROM Dir_Jobs dj WHERE @PostcodeList in (select Location from Dir_Enitiy where EntityId = dj.EntityId) |
|
|
byrdzeye
Starting Member
14 Posts |
Posted - 2010-04-09 : 12:49:56
|
| You can not use a comma separated list in a query. Just won't work that way.Parse the values into a temp table (easy), table variable or table value function and use that.I'm thinking you should use a temp table. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-09 : 14:08:15
|
or doSELECT dj.EntityId, dj.Title, dj.[Description], dj.MediaCodeId, dj.SubCategoryId, dj.CustomerId, dj.SalaryFromId, dj.SalaryToId, dj.HoursId, dj.ContractTypeIdFROM Dir_Jobs djjoin Dir_Enitiy on EntityId = dj.EntityIdWHERE ',' + @PostcodeList + ',' LIKE '%,' + Location +',%' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
craigmacca
Posting Yak Master
142 Posts |
Posted - 2010-04-12 : 04:36:40
|
| ok thanks, so if i parse the values to a temp table how would i do the where??? can you do this??SELECT dj.EntityId, dj.Title, dj.[Description], dj.MediaCodeId, dj.SubCategoryId, dj.CustomerId, dj.SalaryFromId, dj.SalaryToId, dj.HoursId, dj.ContractTypeIdFROM Dir_Jobs djWHERE(select Location from TempTable) in (select Location from Dir_Enitiy where EntityId = dj.EntityId) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-12 : 06:05:04
|
| [code]SELECT dj.EntityId, dj.Title, dj.[Description], dj.MediaCodeId, dj.SubCategoryId, dj.CustomerId, dj.SalaryFromId, dj.SalaryToId, dj.HoursId, dj.ContractTypeIdFROM Dir_Jobs djjoin Dir_Enitiy de on de.EntityId = dj.EntityIdWHERE de.Location in (select Location from TempTable) [/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|