Sql server USP在单元格中查找列文本,并在相应的单元格中插入true或false [英] Sql server USP to find a column text in a cell and insert true or false in the respective cell

查看:123
本文介绍了Sql server USP在单元格中查找列文本,并在相应的单元格中插入true或false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写USP来搜索字符串,该字符串是另一列的单元格中的列名,如果搜索关键字在Searched列中可用,那么对于相应的行,它应插入1(true),如果不是那么0(假)。



让我详细说明:

我的桌子(SearchableTable):

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):

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:

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.

推荐答案

你得到一个列出 sysobjects 中的列或系统视图 INFORMATION_SCHEMA.COLUMNS



您使用光标处理每一行



您使用嵌套光标循环遍历可搜索列,您不解释如何识别可搜索的列!



或者您可以使用CTE但我发现游标更容易调试和理解。
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.


这篇关于Sql server USP在单元格中查找列文本,并在相应的单元格中插入true或false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆