Click here to Skip to main content
15,948,339 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am creating search fuctionality for my 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...
ALTER PROCEDURE [dbo].[sps_search]
@cat nvarchar(100)
	select * from tbl_adregister where category like '%'+@cat+'%'

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).
[no name] 9-May-14 7:28am    
Can't you do a join on the category id?

use SQL JOIN[^]

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
Belwo statement should do the work ;)
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