March 27, 2013 at 8:54 pm
How do I find a word in string? That word stands by itself
In this example, CD is the word, it should only return row 1 row 3 and row 4 as cd appears seperately on those rows.
Table A
Values(varchar)
abbc cd ef
abcdef
adb ef cd
ad cd eg
March 27, 2013 at 11:46 pm
You can use CHARINDEX or PATINDEX for this...
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 28, 2013 at 12:17 am
You can also use this --
Create table #temp
(
name varchar(20)
)
insert into #temp
values ('aaa'),('aa cd ef'),('abcd')
select * from #temp
where name like '% cd%'
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 28, 2013 at 12:23 am
Try -
SELECT*
FROMTableA
WHEREPATINDEX('%[ ]cd[ ]%', [Values]) > 0
OR PATINDEX('%[ ]cd', [Values]) > 0
OR PATINDEX('cd[ ]%', [Values]) > 0
March 28, 2013 at 12:27 am
sohan.fegade (3/28/2013)
Try -SELECT*
FROMTableA
WHEREPATINDEX('%[ ]cd[ ]%', [Values]) > 0
OR PATINDEX('%[ ]cd', [Values]) > 0
OR PATINDEX('cd[ ]%', [Values]) > 0
Hi Sohan, I tried your query but its not returning any value
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 28, 2013 at 1:52 am
This should work..
DECLARE@tbl_Table TABLE
(
Column1 VARCHAR(100)
)
INSERT@tbl_Table
SELECT'abbc cd ef' UNION ALL
SELECT'abcdef' UNION ALL
SELECT'adb ef cd' UNION ALL
SELECT'ad cd eg'
SELECT*
FROM@tbl_Table AS t
WHEREt.Column1 LIKE 'cd %'
ORt.Column1 LIKE '% cd'
ORt.Column1 LIKE '% cd %'
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 28, 2013 at 2:21 am
Hi Kapil, I not sure where you are going wrong, but it should work.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply