Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# tsql check if a word is founded in an array of word ..

Posted on 2013-05-29
Medium Priority
350 Views
for example i have an array contain set of words
i want to check if the variable @word is founded in the array contains set of word
please can you declare of me a array contain set of word and what function or if statement should be witted to check in @word is in @arrayofword
0
Question by:afifosh
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 49

Expert Comment

ID: 39204100
an "array"?
do you have at least one table involved?
please provide us with some more details of what the database stores (e.g. a table) otherwise we are totally guessing.
0

LVL 32

Expert Comment

ID: 39204539
Since we're guessing -
where patindex(@word,@arrayof word) > 0
0

LVL 19

Expert Comment

ID: 39204861
what I'm understanding is

``````declare @str1 varchar(500)
set @str1 = 'angel,sage,master,wizard'

select charindex('master',@str1)
``````
0

LVL 21

Accepted Solution

Jason Yousef, MS earned 1500 total points
ID: 39223165
Not sure what you mean but the result in a new array
what I'm understanding is:
``````Declare @word varchar(100),
@arrayofword  varchar(1000)

select @word = 'visit' , @arrayofword = 'jason, test, visit'

select charindex(@word,@arrayofword)
``````
0

LVL 32

Expert Comment

ID: 39223233
Selecting charindex [or patindex] (@word,@arrayofword) would produce 12 and 14 respectively for the last two offered solutions, so I think what you're looking for is more like select <whatever> where charindex((@word,@arrayofword) > 0
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
###### Suggested Courses
Course of the Month4 days, 22 hours left to enroll