T-sql Search results issue

Hi All,
I used following code to group data and insert into the  Drop down box to search records via users. But im not
getting correct output. i guess because of special characters. i just wondering how to use search  without deleting above
special characters. Any idea appreciate.

Drop down box - sql code
select [Company Name] From database1 GROUP BY [Company Name]

Search code

select [Company Name],Name,[Address 1],[Address 2],[City] From database1  WHERE [Company Name] IN(@CompanyName)
LVL 10
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Data DudeCommented:
Define 'above special characters', and please give us a before and after data set of what you're trying to pull off here.
ukerandiAuthor Commented:
sorry above special characters are
', / ( ) . "
Olaf DoschkeSoftware DeveloperCommented:
I'd say IN(@CompanyName)  is not working as you'd expect. eg even if you set @CompanyName to be a list of values, t-sql takes this in list as a one element list with @CompanyNyme being the one element including all the "special" chars in it.

This is the same as ...WHERE CompanyName = @CompanyName, which should be more obviously not work.

You could use CHARINDEX(...)>0 in this case, more specific
Where CHARINDEX(CompanyName,@CompanyName)>0.

This is not optimized via index on CompanyName, better would be an inner join on a temp table containing the list of companies you're looking for, but it's likely your software won't support defining the temporary table you'd need for that.

Bye, Olaf.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.