Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am creating search fuctionality for my asp.net website. I have one textbox and button, user can enter any search term in textbox and i checks whether it is present in my table or not through stored procedure. @cat parameter contains user search term...
SQL
ALTER PROCEDURE [dbo].[sps_search]
@cat nvarchar(100)
AS
BEGIN
	select * from tbl_adregister where category like '%'+@cat+'%'
END

In table (tbl_adregister) the column(category) stores the category id and there is seperate table(tbl_category) for storing category names(category_name) and id(category_id).
My problem is user enters text value in search box and how can i match it with the table(tbl_category).
Posted
Comments
[no name] 9-May-14 7:28am    
Can't you do a join on the category id?

use SQL JOIN[^]

SQL
select ta.* from tbl_adregister ta join tbl_category tc on ta.category_id =tc.category_id  where tc.category_name like '%'+@cat+'%'
 
Share this answer
 
v2
Belwo statement should do the work ;)
SQL
select r.*, c.*
from tbl_adregister AS r INNER JOIN tbl_category AS c ON r.category = c.category_id
where c.category like %@cat%
 
Share this answer
 

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