Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm trying to write a USP to search a string which is a column name in another column's cell and if the search keyword is available in the Searched column then for the respective row it should insert 1 (true) , if not then 0 (false).

Let me elaborate it:
My table (SearchableTable):
SQL
ID	ArticleColumn	                       Installed	Proactive	process 
234	That was installed on client machine.	1	        0	        0
235	Preparation for all above	            0	        0	        0
236	A proactive process of installation.	0	        1	        1
237	the process in a different way.	        0	        0	        1


The logic:
SQL
ALTER PROCEDURE [dbo].[SerachColumn]
AS
BEGIN

	-- GET the 1st searchable column name 
	-- Search it in the 'ArticleColumn' column
	-- if found insert 1 in the respective cell or 0
	-- Do this for rest of the columns
	-- when the columns finish come to the next row 
	-- and search the 1st column name again in the respective 2nd row of the 'ArticleColumn' 
	-- repeat the process till all the searchable columns and rows finish.
END


Please help.
Posted

1 solution

You get a list if the columns from sysobjects or the system views INFORMATION_SCHEMA.COLUMNS

You use a cursor to process each row

You use a nested cursor to loop through the 'Searchable' columns, you don't explain how you identify the searchable columns!

Or you could use a CTE but I find cursors easier to debug and understand.
 
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