从SQL Server中的字符串中搜索多次出现的单词
我们将一个页面HTML存储在一个表列中。前从SQL Server中的字符串中搜索多次出现的单词,sql,sql-server,Sql,Sql Server,我们将一个页面HTML存储在一个表列中。前 <h3>Introducing the Targus 2014 Educational Range....</h3><span style="font-size: 12px;">Targus has launched its latest educational range. Please <a href="">click here&
<h3>Introducing the Targus 2014 Educational Range....</h3><span style="font-size: 12px;">Targus has launched its latest educational range. Please <a href="">click here</a> for more information. These products are now available for purchase from Dicker Data.<br><br><br>Think Outsid<img src=";fileId=38" style="float: left; width: 176px; margin: 0px 10px 10px 0px;" alt="">eOs Stowaway keyboard, distributed by Targus, is full-sized but folds to a size nearly as small as the Pocket PC itself. The keys are the same size as those on a standard keyboard, requiring little or no adjustment when using the folding keyboard. br><br>&nbsp;Think Outside&nbsp;S<img fileId=39"
我们有一个单词FileID,它在该字符串中重复多次。FileID始终具有分配给ite的值。g FileID=38,FileID=39
我想提取分配给此文件ID的所有数字。预期产量
应具有此字符串的结果集38和39。我尝试了下面的查询,但它只给出了第一个值。任何输入都会有帮助
SELECT SUBSTRING(ArtContent, CHARINDEX('fileId', mycolumn)+7,2) from myTable
问题是代码只检查第一次出现的情况。如果你想搜索更多,你需要 声明一个游标。 将所有ArtContent内容插入其中 获取第一个文件并使用while循环从中获取每个fileId,直到Charindex为-1 将文件ID存储在表中 取下一个重复 从诱惑中选择。 试试这个脚本
DECLARE @A TABLE (STRG VARCHAR (max))
INSERT INTO @A SELECT '<h3>Introducing the Targus 2014 Educational Range....</h3><span style="font-size: 12px;">Targus has launched its latest educational range. Please <a href="">click here</a> for more information. These products are now available for purchase from Dicker Data.<br><br><br>Think Outsid<img src=";fileId=38" style="float: left; width: 176px; margin: 0px 10px 10px 0px;" alt="">eOs Stowaway keyboard, distributed by Targus, is full-sized but folds to a size nearly as small as the Pocket PC itself. The keys are the same size as those on a standard keyboard, requiring little or no adjustment when using the folding keyboard. br><br>&nbsp;Think Outside&nbsp;S<img fileId=39"'
;WITH CTE(MOD_STR,STRG)
AS(
SELECT CONVERT (VARCHAR(MAX),SUBSTRING(STRG,CHARINDEX('FileID=',STRG)+7,2))
,CONVERT (VARCHAR(MAX),SUBSTRING(STRG,CHARINDEX('FileID=',STRG)+9,LEN(STRG)-CHARINDEX('FileID=',STRG))) FROM @A
UNION ALL
SELECT CONVERT (VARCHAR(MAX),MOD_STR +';'+SUBSTRING(STRG,CASE WHEN CHARINDEX('FileID=',STRG)>1 THEN CHARINDEX('FileID=',STRG)+7 ELSE LEN(STRG) END,2))
,CONVERT (VARCHAR(MAX),SUBSTRING(STRG,CASE WHEN CHARINDEX('FileID=',STRG)>1 THEN CHARINDEX('FileID=',STRG)+9 ELSE 0 END
,CASE WHEN CHARINDEX('FileID=',STRG)>1 THEN LEN(STRG)-CHARINDEX('FileID=',STRG) ELSE 0 END))
FROM CTE WHERE CHARINDEX('FileID=',STRG)>1
)
SELECT TOP 1 * FROM CTE ORDER BY LEN(STRG)ASC
选择-Leaddata,
*
从选择
通过选择1作为Id[value],LEAD[value],1通过选择1 LeadData获得订单上的行号
从字符串_SPLIT@str, ' '
泰
其中[Value]=“key:”或编写一个表值函数,并使用OUTER APPLY将其应用于表中的每一行。如果我不只是在打电话,我会这么做。我喜欢它。您应该在@user3441683执行此操作