Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a webform(this webform show search resault)
i have this query for show search resault about a text

SQL
SELECT [ProID], [ProName], [ProCompany], [ProPSale], [ProPic] FROM [Product] WHERE (([ProName] = @ProName) or([ProCompany] = @ProCompany))


this query return many field about product
about product that his name or company = text
i want return product that name or company is contain text(text for search)
a want a query with operator LIKE oR Contain value of @ProName And @ProCompany is in a QueryString
Posted
Updated 21-Jun-12 11:02am
v2

You would use:
SELECT [ProID], [ProName], [ProCompany], [ProPSale], [ProPic] FROM [Product] WHERE (([ProName] LIKE @ProName) or([ProCompany] LIKE @ProCompany))

And then you just have to make sure that when you set the parms @ProName and @ProCompany, that you put a % at the start and the end of the string that you set it to.
 
Share this answer
 
Comments
Maciej Los 21-Jun-12 17:09pm    
Bad example, good commment ;)
5!
Use LIKE & wild card character '%'
Try:
SQL
SELECT 
  [ProID], 
  [ProName], 
  [ProCompany], 
  [ProPSale], 
  [ProPic] 
FROM 
  [Product] 
WHERE (([ProName] LIKE '%'+@ProName+'%') or([ProCompany] LIKE '%'+@ProCompany+'%'))


Refer:
MSDN: LIKE (Transact-SQL)[^]
MSDN: Percent character (Wildcard - Character(s) to Match) (Transact-SQL)[^]
 
Share this answer
 
Comments
Maciej Los 21-Jun-12 17:07pm    
Yes! +5!
Sandeep Mewara 21-Jun-12 23:16pm    
Thanks Mac! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900