I am not a great SQL user and am looking to solve what may be a simple problem. While I eventually will need to "loop thru" a list of strings that is the result of a single column query, I first need to solve this problem:
I would like to use a variable in an SQL Server string function. Here is an example piece of code:
declare @STR nvarchar(50)
set @STR = 'ceo'
SELECT
Document_Text.DocText_ID,
SUBSTRING(Document_Text.DocText, CHARINDEX(@STR, Document_Text.DocText)-125, 250) as SubText
FROM
Document_Text
WHERE
Document_Text.DocText like '%@STR%'
As I described above, I will eventually use the results of a single column query (~200 values) in place of @STR in such a query.
From an application standpoint, consider the following:
- Document_Text holds columns for UserID, DocID, DocURL, and DocText - the last being a text form of a resume. The STR is a short query word(s) - nvarchar(50) - that is searched upon (I know that this may not seem intuitive as a search app, but there is another form of point-n-click processing that uses the results of this query that "makes it make sense").
- My eventual query will grab job role or functional area key words from a single column of another table in the same database.
If anyone has suggestions for this next step, I'd appreciate also. Thanks.