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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select in issue

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.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-09 : 14:08:15
or do


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
join Dir_Enitiy
on EntityId = dj.EntityId
WHERE ',' + @PostcodeList + ',' LIKE '%,' + Location +',%'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

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.ContractTypeId
FROM Dir_Jobs dj
WHERE
(select Location from TempTable) in (select Location from Dir_Enitiy where EntityId = dj.EntityId)
Go to Top of Page

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.ContractTypeId
FROM Dir_Jobs dj
join Dir_Enitiy de
on de.EntityId = dj.EntityId
WHERE de.Location in
(select Location from TempTable)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -